您的位置:首页 > 产品设计 > UI/UE

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

2016-03-17 09:42 886 查看
今天用了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];就好了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: