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];
}
您像往常一样从键盘通知中获取动画曲线,并通过位移将其转换为动画选项。
For whatever reason, the animation curve reported on keyboard dismissal is incorrect. It seems to actually be 6 << 16 instead of 7 << 17.
Here's what I do with UIKeyboardWillChangeFrameNotification
to determine which animation curve to use.
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){
}];
Basically I determine if the keyboard frame is hiding by seeing if the new y origin will be just outside our view's frame (newConstant
). Then based on that I use either 6 or 7:
newConstant == 0 ? (6 << 16) : (7 << 16)
The rest is just adjusting my tableView
contentInset
and scrollIndicatorInsets
, as well as changing the constant on the toolbar that is moving with the keyboard.