今天用了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];就好了