Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8 - prevent rotation on presenting viewController

We have a MainViewController with a tableView, and it presents a new modalViewController.

The MainViewController is restricted to portrait only, and the modalViewController can rotate.

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

Thus, the UITableView is getting its data reloaded, which is a behaviour we don't want.

Can we prevent this feature of iOS 8, and not rotate the presenting UIViewController?

like image 982
oren Avatar asked Feb 11 '15 09:02

oren


1 Answers

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.

like image 194
oren Avatar answered Nov 16 '22 00:11

oren