Search code examples
iosorientationmpmovieplayercontrollerautolayoutportrait

iOS 6 - Tab Bar controller locked to portrait except when presenting modal MPMoviePlayerViewController


I have an tab bar app that has several views. Each view should be locked to Portrait mode, except when displaying a video in a movieviewcontroller. What is the proper way to set this up?

App is for iOS 6.0 and above, and uses autolayout.


Solution

  • Just had to create a category for UITabBarController with these methods:

    -(BOOL)shouldAutorotate{
        return YES;
    }
    - (NSInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
    }
    

    Then in my subclassed MPMoviePlayerViewController:

    -(BOOL)canBecomeFirstResponder{
        return YES;
    }
    
    -(BOOL)canResignFirstResponder{
        return YES;
    }
    
    -(BOOL)shouldAutorotate{
        return true;
    }
    
    -(NSUInteger)supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskAll;
    }
    

    Now all the tab views are locked to portrait / upside down portrait while the movie player is free to rotate in any orientation.