如何设置键盘的动画时间

时间:2011-04-01 12:22:06

标签: iphone cocoa-touch animation uiview keyboard

希望是一个基本问题:是否有一种简单的方法来改变键盘弹出的速度?我可以在我的ViewDidLoad方法中执行此操作:

[UIView setAnimationDuration:2.5];

它不仅会影响我的键盘弹出的速度(死慢),还会影响所有其他动画,如光标动画(也慢死)。有没有办法单独锁定键盘的速度? [UIView.firstResponder setAnimationDuration:2.5];无效。

1 个答案:

答案 0 :(得分:1)

我想我确实需要这个:

// Get the duration of the animation.
NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration;
[animationDurationValue getValue:&animationDuration];

// Animate the resize of the text view's frame in sync with the keyboard's appearance.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:animationDuration];

textView.frame = newTextViewFrame;

[UIView commitAnimations];

我在Apple的示例代码中发现了这一点,该代码说明了如何在键盘顶部添加一个条形码。但是当我在其他地方读到animationDuration只读时,我仍然感到有些困惑。无论如何,这是有效的,所以我想这是我的问题的答案。