我希望确定键盘的动画效果。在iOS 6上,我得到UIKeyboardAnimationCurveUserInfoKey
的有效值(应该是UIViewAnimationCurve
,值为0-3)但是函数返回值7.键盘如何设置动画?使用7的值可以做什么?
NSConcreteNotification 0xc472900 {name = UIKeyboardWillChangeFrameNotification; userInfo = {
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 588}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 372}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";
UIKeyboardFrameChangedByUserInteraction = 0;
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 264}, {320, 216}}";
}}
答案 0 :(得分:21)
键盘似乎正在使用未记录/未知的动画曲线。
但你仍然可以使用它。要将它转换为用于块动画的UIViewAnimationOptions,请将其移位16位,如此
UIViewAnimationCurve keyboardTransitionAnimationCurve;
[[notification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey]
getValue:&keyboardTransitionAnimationCurve];
keyboardTransitionAnimationCurve |= keyboardTransitionAnimationCurve<<16;
[UIView animateWithDuration:0.5
delay:0.0
options:keyboardTransitionAnimationCurve
animations:^{
// ... do stuff here
} completion:NULL];
或者只是将其作为动画曲线传递。
UIViewAnimationCurve keyboardTransitionAnimationCurve;
[[notification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey]
getValue:&keyboardTransitionAnimationCurve];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:keyboardTransitionAnimationCurve];
// ... do stuff here
[UIView commitAnimations];
答案 1 :(得分:1)
不幸的是我无法发表评论,否则我不会输入新答案。
您也可以使用:
animationOptions | = animationCurve&lt;&lt; 16;
这可能是首选,因为它会在animationOptions上保留先前的OR =操作。
答案 2 :(得分:0)
在Swift 4中
func keyboardWillShow(_ notification: Notification!) {
if let info = notification.userInfo {
let keyboardSize = info[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
let duration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
let curveVal = (info[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue ?? 7 // default value for keyboard animation
let options = UIView.AnimationOptions(rawValue: UInt(curveVal << 16))
UIView.animate(withDuration: duration, delay: 0, options: options, animations: {
// any operation to be performed
}, completion: nil)
}
}