在iOS7中的viewWillDisappear期间,无法再隐藏键盘 [英] No longer able to hide keyboard during viewWillDisappear in iOS7

查看:151
本文介绍了在iOS7中的viewWillDisappear期间,无法再隐藏键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在iOS6中用于在视图控制器弹出导航堆栈时隐藏键盘:

   - (void)viewWillDisappear:(BOOL)动画{
[self.view endEditing:YES];
[super viewWillDisappear:animated];
}

然而,在iOS7中,[self.view endEditing:YES]行似乎被忽略我在其他视图事件(viewDidDisappear,viewWillAppear和viewDidAppear)中尝试了该命令,并且它唯一使用的是viewDidAppear。似乎一旦启动pop,我们将无法隐藏键盘,直到视图控制器被推回到堆栈上。



放置viewDidAppear中的代码确实可以隐藏键盘,不好的是当viewController被推回到导航堆栈时键盘会短暂显示......从UI的角度来看,这是非常不可接受的。



有没有其他人成功解决这个问题?我不想写自己的CANCEL按钮,但是现在,这是我能想到的唯一可行的方法。

解决方案

如果是 UITextView 可编辑属性设置为。我尝试了这个,它一旦设置就隐藏了键盘。我没有尝试使用 UITextField ,但我猜你在设置启用时会得到相同的结果属性。如果这不起作用,请创建一个 UITextField ,其中 userInteractionEnabled 设置为作为透明 UITextView 的背景,并使用上面所述的可编辑属性。


The following code used to work in iOS6 to hide the keyboard when a view controller was popped off of the navigation stack:

- (void)viewWillDisappear:(BOOL)animated {
    [self.view endEditing:YES];
    [super viewWillDisappear:animated];
}

However, in iOS7, the [self.view endEditing:YES] line seems to get ignored. I tried the command in other view events (viewDidDisappear, viewWillAppear, and viewDidAppear), and the only one it worked in is viewDidAppear. It seems that once a "pop" is initiated, we lose the ability to hide the keyboard until the view controller is "pushed" back on the stack.

While placing the code in viewDidAppear does work to hide the keyboard, the bad thing is that the keyboard is displayed briefly when the viewController is pushed back on to the navigation stack...pretty unacceptable from a UI perspective.

Has anyone else had success in working around this issue? I would prefer not to have to write my own CANCEL button, but right now, that is the only thing I can think of that will work.

解决方案

If it's a UITextView set the editable property to NO. I tried this and it hides the keyboard as soon as it's set. I haven't tried it with a UITextField but I'm guessing you'd get the same result with setting the enabled property to NO. If that doesn't work, create a UITextField with userInteractionEnabled set to NO as a background for a transparent UITextView and use the editable property as stated above.

这篇关于在iOS7中的viewWillDisappear期间,无法再隐藏键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆