iOS8 - prevent rotation on presenting viewController

六眼飞鱼酱① 提交于 2019-11-30 06:56:09

So after long days of searching and investigating, I finally came up with a possible solution.

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.

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.

Finally, I figured out that I can show this "modal" viewController in another UIWindow. I create UIWindow and set the modalViewController as its rootViewController.

I put some example project in git: https://github.com/OrenRosen/ModalInWindow

Hope it will be helpful.

I did something similar with a navigation controller, that wouldn't rotate unless the top pushed controller does rotate.

In your case check if the main controller is presenting another controller. If it isn't then just reject rotation, otherwise return whatever the presented controller returns for the rotation method.

As for your table view, it shouldn't get reloaded because of rotations.

In iOS 8 the view that rotates when you change the device orientation is the first view added to the UIWindow. So, if you save a reference to it in your presentedController, you can overwrite the shouldAutorotate and supportedInterfaceOrientations values.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!