我希望确定键盘将如何动画。在iOS 6上,我得到了UIKeyboardAnimationCurveUserInfoKey的一个有效值(它应该是一个值为0-3的UIViewAnimationCurve ),但是函数返回的值是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}}";
}}发布于 2013-10-21 09:31:29
似乎键盘使用的是一条未记录的/未知的动画曲线。
但你还是可以用的。若要将其转换为块动画的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];发布于 2014-06-07 19:50:46
不幸的是,我不能发表评论,否则我将不会输入一个新的答案。
您还可以使用:
animationOptions |= animationCurve << 16;
这可能是首选的,因为它将保留以前在animationOptions上的OR =操作。
发布于 2019-04-02 07:59:18
在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)
}
}https://stackoverflow.com/questions/19482573
复制相似问题