iOS7的动画效果与iOS6不同,它们似乎使用了不同的贝塞尔曲线。iOS6使用的是一种“easeInOutSine”曲线,而iOS7更像是“easeInOutExpo”曲线。(http://matthewlein.com/ceaser/)
有没有办法使用这个曲线?我想在键盘打开或关闭时同步我的动画。
iOS7的动画效果与iOS6不同,它们似乎使用了不同的贝塞尔曲线。iOS6使用的是一种“easeInOutSine”曲线,而iOS7更像是“easeInOutExpo”曲线。(http://matthewlein.com/ceaser/)
有没有办法使用这个曲线?我想在键盘打开或关闭时同步我的动画。
这是我的做法(至少当键盘即将显示时)
- (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];
}
像往常一样,您可以从键盘通知中获取动画曲线,并通过位移将其转换为动画选项。
出于某种原因,在键盘消失时报告的动画曲线是不正确的。实际上,它似乎是6 << 16而不是7 << 17。
下面是我使用UIKeyboardWillChangeFrameNotification
来确定要使用哪个动画曲线的方法。
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
的contentInset
和scrollIndicatorInsets
,以及更改随着键盘移动的工具栏上的常量。