Showing keyboard at the right time iOS7(在正确的时间显示键盘iOS7)
问题描述
在 iOS 6 中,我习惯于在 viewDidLoad 中显示键盘.
In iOS 6 I'm used to present keyboard in viewDidLoad.
- (void)viewDidLoad
{
[super viewDidLoad];
[txtField becomeFirstResponder];
}
这样,当navigationController推送新的viewController时,键盘已经存在,从左到右平滑动画,避免了自底向上的动画.
This way, when navigationController pushes the new viewController, keyboard is already there, animating smoothly from left to right and avoiding bottom-up animation.
在 iOS 7 中,这种行为似乎被破坏了.
In iOS 7 this behavior seems broken.
如果我在 viewDidLoad 中添加 [txtField becomeFirstResponder],键盘出现在推送动画的中间,已经在它的最终位置:一个不愉快的效果!!
If I add [txtField becomeFirstResponder] in viewDidLoad, keyboard appears in the middle of pushing animation, already in its final position: an unpleasant effect!!
我尝试在viewWillAppear中移动[txtField becomeFirstResponder],但最终结果没有改变.
I've tried to move [txtField becomeFirstResponder] in viewWillAppear, but the final result is unchanged.
你知道一种方法来恢复 iOS 6 的行为,将新的 viewController 和键盘一起推送吗?
Do you know a way to get back iOS 6 behavior, pushing the new viewController and the keyboard all together?
使用计时器也不起作用...无论我设置什么时间延迟,键盘仅在推动动画结束时显示.
Using a timer doesn't work either... whatever time delay I set, the keyboard is shown only at the end of pushing animation.
到目前为止,我最好的尝试是将 [txtField becomeFirstResponder] 放在 viewWillLayoutSubviews 或 viewDidLayoutSubviews 中.不幸的是,在推送 viewController 时这样做有效,但在弹回时无效(键盘没有出现).
So far, my best try it is to put [txtField becomeFirstResponder] in viewWillLayoutSubviews or viewDidLayoutSubviews. Unfortunately, doing so working when pushing viewController but not when popping back (the keyboard doesn't appear).
推荐答案
我已经设法在 viewWillLayoutSubviews 中推断出您的解决方法以强制它工作.
I've managed to extrapolate your workaround in viewWillLayoutSubviews to force it to work.
- (void)viewWillLayoutSubviews {
if (![self.textField1 isFirstResponder] && ![self.textField2 isFirstResponder] && ...) {
[self.textField1 becomeFirstResponder];
}
}
这对我来说既适用于推入堆栈,也适用于关闭模态视图控制器后.
This is working for me for both pushing onto the stack, and after dismissing a modal view controller.
这篇关于在正确的时间显示键盘iOS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在正确的时间显示键盘iOS7
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
