Super slow lag/delay on initial keyboard animation of UITextField(UITextField 的初始键盘动画的超慢滞后/延迟)
问题描述
好吧,这个问题让我发疯了.
Alright, this problem has been driving me nuts.
触摸 UITextField 后,键盘弹出大约需要 3-4 秒.这仅在应用启动后第一次弹出键盘时发生,之后动画立即开始.
It takes roughly 3-4 seconds for the keyboard to pop up after I touch my UITextField. This only occurs on the first time the keyboard pops up since the app launched, afterwards the animation starts instantly.
一开始我以为是加载太多图片的问题,或者我的UITableView,但我刚刚创建了一个只有一个UITextField的全新项目,我仍然遇到这个问题.我正在使用 iOS 5、Xcode 4.2 版,并在 iPhone 4S 上运行.
At first I thought it was problem of loading too many images, or my UITableView, but I just created a brand new project with only a UITextField, and I still experience this problem. I'm using iOS 5, Xcode ver 4.2, and running on an iPhone 4S.
这是我的代码:
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 20, 280, 30)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.delegate = self;
[self.view addSubview:textField];
}
@end
这是所有应用程序的共同问题吗?
Is this a common problem for all apps?
现在,我可以让它变得更好的唯一方法是让 textField 在 viewDidAppear 中成为/退出第一响应者,但这并不能完全解决问题- 它只是将延迟加载到视图加载时.如果我在视图加载时立即单击 textField,我仍然会遇到问题;如果我在视图加载后等待 3-4 秒再触摸 textField,我不会得到延迟.
Right now, the only way I can make it somewhat better is by having textField become/resign first responder in viewDidAppear, but that doesn't solve the problem entirely - it just loads the delay onto when the view loads instead. If I click on textField immediately when the view loads, I still get the problem; if I wait 3-4 seconds after the view loads before touching the textField, I don't get the delay.
推荐答案
所以问题不只是像我之前想象的那样仅限于第一次安装,而是每次启动应用程序时都会发生.这是我完全解决问题的解决方案.
So the problem is NOT just limited to the first install as I had previously thought, but happens every time the app is launched. Here's my solution that solves the issue completely.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Preloads keyboard so there's no lag on initial keyboard appearance.
UITextField *lagFreeField = [[UITextField alloc] init];
[self.window addSubview:lagFreeField];
[lagFreeField becomeFirstResponder];
[lagFreeField resignFirstResponder];
[lagFreeField removeFromSuperview];
}
这篇关于UITextField 的初始键盘动画的超慢滞后/延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITextField 的初始键盘动画的超慢滞后/延迟
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
