解决做Mansonry/Autolayout动画时,uitextfield中的文字会向上抖动或跳动的问题

来源:互联网 发布:西工大矩阵论课件 编辑:程序博客网 时间:2024/06/04 18:44

今天用了Masonry做了一个动画,动画的时候发生了一个奇怪的现象
居然画面中所有的UITextfield在切换焦点的里面文字都向上抖动一下或者说是跳动一下。醉醉的 ,后来改了一行代码就好了初始代码如下

+(BOOL)requiresConstraintBasedLayout{    return YES;}-(void)updateConstraints{    [self.imgCompanyIcon mas_updateConstraints:^(MASConstraintMaker *make) {        make.centerX .equalTo(self.mas_centerX);        make.width.equalTo(@90);        make.height.equalTo(@90);        make.top.equalTo(self.mas_top).with.offset(86 -180*self.isKeybordShow);    }];    [super updateConstraints];}#pragma mark - Keyboard Notification-(void)keyboardWillShow:(NSNotification *)notifi{    NSDictionary* userInfo = [notifi userInfo];    NSValue* animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];    NSTimeInterval animationDuration;    [animationDurationValue getValue:&animationDuration];    self.isKeybordShow = YES;    [self setNeedsUpdateConstraints];    [self updateConstraintsIfNeeded];    [UIView animateWithDuration:animationDuration animations:^{        [self layoutIfNeeded];    }];}

最后发现只要将最后一句[self layoutIfNeeded];改为[self layoutSubviews];就好了

2 0
原创粉丝点击