首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIKeyboardWillChangeFrameNotification UIViewAnimationCurve设置为iOS 7上的7

UIKeyboardWillChangeFrameNotification UIViewAnimationCurve设置为iOS 7上的7
EN

Stack Overflow用户
提问于 2013-10-20 20:36:10
回答 3查看 4K关注 0票数 6

我希望确定键盘将如何动画。在iOS 6上,我得到了UIKeyboardAnimationCurveUserInfoKey的一个有效值(它应该是一个值为0-3的UIViewAnimationCurve ),但是函数返回的值是7。键盘是如何动画的?7的值能做些什么?

代码语言:javascript
复制
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}}";
}}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-10-21 09:31:29

似乎键盘使用的是一条未记录的/未知的动画曲线。

但你还是可以用的。若要将其转换为块动画的UIViewAnimationOptions,请将其移动16位,如下所示

代码语言:javascript
复制
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];

或者把它当作动画曲线来传递。

代码语言:javascript
复制
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];
票数 21
EN

Stack Overflow用户

发布于 2014-06-07 19:50:46

不幸的是,我不能发表评论,否则我将不会输入一个新的答案。

您还可以使用:

animationOptions |= animationCurve << 16;

这可能是首选的,因为它将保留以前在animationOptions上的OR =操作。

票数 1
EN

Stack Overflow用户

发布于 2019-04-02 07:59:18

在Swift 4

代码语言:javascript
复制
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)
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19482573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档