简体   繁体   English

我应该先关闭键盘再关闭视图吗?

[英]Should I dismiss keyboard before dismissing the view?

I have two UIViewControllers , on modally presented over the other. 我有两个UIViewControllers ,以模态形式呈现在另一个之上。 The first controller is orientated in landscape, and the modal view is presented in portrait. 第一个控制器以横向放置,模态视图以纵向显示。

When dismissing the modal view, the view animates to reveal the landscape view below. 消除模式视图时,该视图会设置动画以显示下面的风景视图。 If the keyboard is visible on the modal view at this time, it will suddenly attach itself to the left or right side of the screen to match the orientation of the soon-to-be active viewController. 如果此时键盘在模式视图中可见,它将突然将其自身附着在屏幕的左侧或右侧,以匹配即将启用的viewController的方向。

Is there a way to let the keyboard disappear in the same orientation as the disappearing viewController? 有没有办法让键盘以与消失的viewController相同的方向消失? Or should I perhaps dismiss the keyboard before dismissing the modal view controller? 还是应该关闭模式视图控制器之前关闭键盘? In that case, what would be the best approach? 在这种情况下,最好的方法是什么?

I do have an action for when the user clicks 'close'. 当用户单击“关闭”时,我确实有一个动作。 I can there check if any objects are firstResponder, and start a timer for ~0.4 seconds before dismissing.. But it would obviously create a kind of delay that wouldn't feel all that natural.. I'd prefer a way to let the keyboard stay attached to the same orientation as the dismissing view. 我可以在那里检查是否有任何对象是firstResponder,并在关闭前将其启动〜0.4秒。.但是,这显然会造成某种延迟,这种感觉不会很自然。.我更喜欢一种让键盘保持与解像视图相同的方向。

This is happening: 这正在发生:

键盘解雇错误

I think the best practice would be to dismiss the keyboard before dismissing your modal ViewController. 我认为最好的做法是在解散模态ViewController之前先解散键盘。 The keyboard is presented over your content and should be removed first before removing other items in the view hierarchy. 键盘显示在您的内容上,应先删除键盘,然后再删除视图层次结构中的其他项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM