我一直在做类似的事情来模仿旧版本 iOS 上的键盘动画。
CGRect keyboardBeginFrame;
[[note.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&keyboardBeginFrame];
self.doneKeyboardButton.frame = CGRectMake(0, (keyboardBeginFrame.origin.y + keyboardBeginFrame.size.height) - 53, 106, 53);
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:self.doneKeyboardButton];
CGPoint newCenter = CGPointMake(self.doneKeyboardButton.superview.frame.origin.x + self.doneKeyboardButton.frame.size.width/2,
self.doneKeyboardButton.superview.frame.size.height - self.doneKeyboardButton.frame.size.height/2);
[UIView animateWithDuration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]-.02
delay:.0
options:[[note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]
animations:^{
self.contentView.frame = CGRectOffset(self.contentView.frame, 0, -TextFieldViewMovement);
self.doneKeyboardButton.center = newCenter;
}
completion:nil];
然而,这在 iOS7 上已经停止工作。返回的值似乎不再完全正确,并且“完成”按钮不再完全模仿键盘显示动画。
在 iOS 7 中,键盘使用了新的、未记录的动画曲线。虽然有些人指出使用未记录的动画选项值是有效的,但我更喜欢使用以下内容:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
[UIView setAnimationCurve:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue]];
[UIView setAnimationBeginsFromCurrentState:YES];
// work
[UIView commitAnimations];
虽然建议使用基于块的动画,但从键盘通知返回的动画曲线是UIViewAnimationCurve
,而您需要传递给基于块的动画的选项是UIViewAnimationOptions
。使用传统的 UIView 动画方法可以让您直接通过管道输入值。最重要的是,这将使用新的未记录的动画曲线(整数值 7)并使动画与键盘匹配。而且,它在 iOS 6 和 7 上也能正常工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)