如何使用默认的iOS7 UIAnimation曲线

iOS7animation的行为与iOS6中的行为不同。 他们似乎使用不同的贝塞尔曲线。 在iOS6使用一种“easeInOutSine”曲线的情况下,iOS7更像是“easeInOutExpo”types。 ( http://matthewlein.com/ceaser/ )

有没有办法使用这条曲线? 我想在键盘打开/closures时同步我的animation。

这是我如何做到的(至less当键盘即将被显示时)

- (void)keyboardWillShow:(NSNotification *)notification { NSDictionary *keyboardAnimationDetail = [notification userInfo]; UIViewAnimationCurve animationCurve = [keyboardAnimationDetail[UIKeyboardAnimationCurveUserInfoKey] integerValue]; CGFloat duration = [keyboardAnimationDetail[UIKeyboardAnimationDurationUserInfoKey] floatValue]; [UIView animateWithDuration:duration delay:0.0 options:(animationCurve << 16) animations:^{ // Set the new properties to be animated here } completion:nil]; } 

您可以像平常一样从键盘通知中获取animation曲线,并通过位移将其转换为animation选项。

更新,在7.1中修复。 不再需要。


无论出于何种原因,键盘解除报告的animation曲线都是不正确的。 看来实际上是6·16而不是7·17。

以下是我使用UIKeyboardWillChangeFrameNotification确定要使用的animation曲线。

 NSDictionary *keyboardAnimationDetail = [notification userInfo]; CGRect keyboardEndFrameWindow = [keyboardAnimationDetail[UIKeyboardFrameEndUserInfoKey] CGRectValue]; double keyboardTransitionDuration = [keyboardAnimationDetail[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // gives incorrect value of 7 on dismissal // UIViewAnimationCurve keyboardTransitionAnimationCurve = [keyboardAnimationDetail[UIKeyboardAnimationCurveUserInfoKey] integerValue]; CGRect keyboardEndFrameView = [self.view convertRect:keyboardEndFrameWindow fromView:nil]; CGFloat newConstant = (self.view.frame.size.height - keyboardEndFrameView.origin.y); [UIView animateWithDuration:keyboardTransitionDuration delay:0.0f options:newConstant == 0 ? (6 << 16) : (7 << 16) animations:^{ self.tableView.contentInset = UIEdgeInsetsMake(self.tableView.contentInset.top, 0, self.view.frame.size.height - keyboardEndFrameView.origin.y + self.commentToolbar.frame.size.height, 0); self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(self.tableView.scrollIndicatorInsets.top, 0, self.view.frame.size.height - keyboardEndFrameView.origin.y + self.commentToolbar.frame.size.height, 0); self.commentViewToSuperviewBottomConstraint.constant = (self.view.frame.size.height - keyboardEndFrameView.origin.y); [self.view layoutIfNeeded]; } completion:^(__unused BOOL finished){ }]; 

基本上,我通过查看新的y原点是否在我们视图的框架之外( newConstant )来确定键盘框架是否隐藏。 然后根据我使用6或7:

newConstant == 0 ? (6 << 16) : (7 << 16)

其余的只是调整我的tableView contentInsetscrollIndicatorInsets ,以及更改与键盘一起移动的工具栏上的常量。