iOS8 - 阻止呈现viewController时的旋转 [英] iOS8 - prevent rotation on presenting viewController
问题描述
我们有一个带有tableView的MainViewController,它提供了一个新的modalViewController。
We have a MainViewController with a tableView, and it presents a new modalViewController.
MainViewController仅限于纵向,modalViewController可以旋转。
The MainViewController is restricted to portrait only, and the modalViewController can rotate.
问题出在iOS8中,当modalViewController旋转时,MainViewcontroller中iOS8中的旋转回调方法被调用 - - (void)viewWillTransitionToSize :(CGSize)size withTransitionCoordinator:(id< UIViewControllerTransitionCoordinator>)coordinator
The problem is in iOS8, that when the modalViewController rotates, the callback method of rotation in iOS8 in MainViewcontroller is called - - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
因此,UITableView正在重新加载其数据,这是一种行为我们不想要。
Thus, the UITableView is getting its data reloaded, which is a behaviour we don't want.
我们可以阻止iOS 8的这个功能,而不是旋转呈现的UIViewController吗?
Can we prevent this feature of iOS 8, and not rotate the presenting UIViewController?
推荐答案
经过漫长的搜索和调查,我终于想出了一个可能的解决方案。
So after long days of searching and investigating, I finally came up with a possible solution.
首先,我可以使用导航控制器和推送viewController而不是呈现它,但它破坏了我的代码而且不是那么真实。
First of all, I can use navigation controller and push the viewController instead of presenting it, but it breaks my code and just isn't so true.
我能做的第二件事就是不设置约束。我仍然可以使用autolayout,但是如果我没有设置约束,并且设置了默认约束,则不会重新加载tableView。当然这也不是很聪明的事情,因为我在viewController中有很多元素。
The second thing I can do is not setting constraints. I still can use autolayout, but if I don't set constraints, and let the default constraints to be set, the tableView doesn't get reloaded. of course this is also isn't very smart thing to do, as I have many elements in my viewController.
最后,我发现我可以显示这个模态 另一个UIWindow中的viewController。我创建了UIWindow并将modalViewController设置为它的rootViewController。
Finally, I figured out that I can show this "modal" viewController in another UIWindow. I create UIWindow and set the modalViewController as its rootViewController.
我在git中放了一些示例项目:
https://github.com/OrenRosen/ModalInWindow
I put some example project in git: https://github.com/OrenRosen/ModalInWindow
希望它会有所帮助。
这篇关于iOS8 - 阻止呈现viewController时的旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!