我可以通过以下步骤触发这个问题:
创建两个
UIViewController
的子类:ViewControllerA
和ViewControllerB
在
ViewControllerA
中实现supportedInterfaceOrientations
方法并返回UIInterfaceOrientationMaskPortrait
在
ViewControllerB
中实现supportedInterfaceOrientations
方法并返回UIInterfaceOrientationMaskLandscape
创建一个名为
NavigationController
的UINavigationController
子类,实现supportedInterfaceOrientations
方法并返回[self.topViewController supportedInterfaceOrientations]
(这样做是因为我想保持导航控制器及其根视图控制器不旋转)将
NavigationController
作为应用程序的初始视图控制器,将ViewControllerA
设置为NavigationController
的rootViewContrller
启动应用程序,
ViewControllerA
将以纵向模式显示。在ViewControllerA
上显示一个按钮,按下该按钮将使用presentViewController:animated:completion
方法呈现ViewControllerB
ViewControllerB
将以横向模式显示;在ViewControllerB
上显示一个文本字段,点击文本字段将触发键盘,但是键盘处于纵向模式,就像上面的图片一样。
PS. 您可以下载并运行Xcode项目在Github上
这个问题似乎只出现在iOS 8.3上。我做错了什么吗?还是这只是iOS的另一个bug?
顺便说一下,如果您直接显示ViewControllerA
而没有ViewController
,则不会出现此问题。因此,如果这是iOS的一个bug,我如何避免从子类化UINavigationController
但仍保持ViewControllerA
,它是UINavigationController
的rootViewController,不旋转。
更新:这个bug仍然在iOS 8.4上出现,我已经提交了一个bug报告,并于2015年6月17日收到了苹果的回复,他们说已经在最新的iOS 9测试版中解决了这个问题。