Search code examples
uiviewcontrolleruiwindowuiinterfaceorientation

Only direct subviews of the MainWindow view gets orientation set by iOS?


Whenever my app is rotated, only the viewController of which I've added his view as a subview to the mainwindow gets his interfaceOrientation property updated, the rest remains ignorant of the fact the device has been rotated.

Is it my responsibilty to notify other objects of the change, and if so, what's a nice way to do it?

I've looked into setting interfaceOrientation of my children-viewcontrollers but that's readonly.

Thanks in advance,


Solution

  • I found that calling

    willRotateToInterfaceOrientation
    

    and/or

    didRotateFromInterfaceOrientation
    

    of the view controller you are going to show worked for me. In my case I was using a Navigation Controller so it was easy to keep track of what was going to be shown to the user next. Below is some code from my project.

    - (void)navigationController:(UINavigationController *)navigationController 
             didShowViewController:(UIViewController *)viewController 
             animated:(BOOL)animated {
        [viewController willRotateToInterfaceOrientation:
            [self interfaceOrientation] duration:0];    
    }