iOS 7 键盘动画
iOS 7 键盘弹出用了一个新的 UIViewAnimationOptionCurve。其值为 7,但不论头文件还是文档都没有提及这个新的 curve。
头文件中的 curve 一览:
UIViewAnimationOptionCurveEaseInOut = 0 << 16, // default UIViewAnimationOptionCurveEaseIn = 1 << 16, UIViewAnimationOptionCurveEaseOut = 2 << 16, UIViewAnimationOptionCurveLinear = 3 << 16 …
在 iOS 7 之前,键盘是使用的默认的 UIViewAnimationOptionCurveEaseInOut,如果你的 App 有控件跟随键盘移动(比如聊天界面下的输入框),并且使用这个 curve,则在 iOS 7 下会有类似这样的不正确的效果。
注:为突出效果,此处用的 UIViewAnimationOptionCurveLinear。
可以参考 QQ,就有这个问题(微信没有)。
而正确的做法是从键盘的通知中取出 curve 来使用,比如:
- (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; } - (void)keyboardWillShow:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; NSTimeInterval animationDuration; UIViewAnimationCurve animationCurve; [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration]; [[info objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve]; UIViewAnimationOptions options = animationCurve << 16; [UIView animateWithDuration:animationDuration delay:0.0f options:options animations:^ { self.constraintInputView2Bottom.constant = kbSize.height; [self.view layoutIfNeeded]; } completion:nil]; }
为什么注册的 keyboardWillShown notification,结果用keyboardWillHide 的 method 呢....