如何在 iOS 7 上模拟键盘动画以添加“完成"数字键盘的按钮?

How to mimic Keyboard animation on iOS 7 to add quot;Donequot; button to numeric keyboard?(如何在 iOS 7 上模拟键盘动画以添加“完成数字键盘的按钮?)
本文介绍了如何在 iOS 7 上模拟键盘动画以添加“完成"数字键盘的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我一直在做类似的事情来模仿旧版本 iOS 上的键盘动画.

I had been doing something like this to mimic the keyboard animation on older version of 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 上运行.返回的值似乎不再完全正确,并且完成"按钮不再完全模仿键盘显示动画.

However, this has stopped working on iOS7. It seems like the values returned are no longer exactly correct, and the Done button no longer exactly mimics the Keyboard display animation.

推荐答案

在 iOS 7 中,键盘使用新的、未记录的动画曲线.虽然有些人注意到对动画选项使用未记录的值是可行的,但我更喜欢使用以下内容:

In iOS 7, the keyboard uses a new, undocumented animation curve. While some have noted that using an undocumented value for the animation option works, I prefer to use the following:

[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.

While block based animations are the recommendation, the animation curve returned from the keyboard notification is an UIViewAnimationCurve, while the option you would need to pass to block based animations is an UIViewAnimationOptions. Using the traditional UIView animation methods allows you to pipe the value directly in. Most importantly, this will use the new undocumented animation curve (integer value of 7) and cause the animation to match the keyboard. And, it will work just as well on iOS 6 and 7.

这篇关于如何在 iOS 7 上模拟键盘动画以添加“完成"数字键盘的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to resize UITextView on iOS when a keyboard appears?(出现键盘时如何在iOS上调整UITextView的大小?)
How to reliably detect if an external keyboard is connected on iOS 9?(如何可靠地检测 iOS 9 上是否连接了外部键盘?)
How do I dismiss the iOS keyboard?(如何关闭 iOS 键盘?)
Is possible to simulate touch event using an external keyboard on ios jailbroken?(是否可以在 ios 越狱后使用外部键盘模拟触摸事件?)
How do I retrieve keystrokes from a custom keyboard on an iOS app?(如何从 iOS 应用程序上的自定义键盘检索击键?)
UIKeyboardFrameBeginUserInfoKey amp; UIKeyboardFrameEndUserInfoKey(UIKeyboardFrameBeginUserInfoKey amp;UIKeyboardFrameEndUserInfoKey)