Resolved Video won't rotate to landscap in iOS 6

Discussion in 'iOS Programming' started by straber, May 1, 2013.

  1. straber, May 1, 2013
    Last edited: May 2, 2013

    straber macrumors member

    Joined:
    Jul 3, 2012
    #1
    I know this question has already been asked a bazillion times, but none of the solutions I've found so far have worked. Here's the situation, I have an app in which every view supports only portrait mode except for a subclass of MPMoviePlayerViewController which supports landscape left and right as well. This view is being presented modally from within a UINavigationController, so I have subclassed UINavigationController as well and that subclass supports landscape as well. I have made sure that the project file is set up to support all orientations except upside down. The code in my movie player subclass for rotation is this:

    Code:
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }
    
    - (BOOL)shouldAutorotate {
        return YES;
    }
    This works fine in iOS 5.x, but it won't ever leave portrait mode in iOS 6. Does anyone have any ideas about what else I can do make the movie rotate in iOS 6?

    Thanks
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Why did you feel it necessary to subclass MPMoviePlayerViewController and UINavigationController? Also, which method are you using to present your modal view?
     
  3. straber thread starter macrumors member

    Joined:
    Jul 3, 2012
    #3
    Well after doing exhaustive google searches for an answer, I saw some posts from people saying that it solved their problem to subclass those and explicitly say what orientations they support. I tried it both with and without subclassing them and it made no difference for me, I only mentioned it to let everyone know that I had already tried this.

    I'm presenting the movie player using:

    presentMoviePlayerViewControllerAnimated:
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Assuming you're dealing with an iOS 6+ app, here's what I got to work in a test project:
    1. At the project-level (i.e. in the Summary tab), set the Supported Interface Orientations so that Portrait, Landscape Left, and Landscape Right are selected.
    2. Subclass UINavigationController and override the supportedInterfaceOrientations method so that it only returns UIInterfaceOrientationMaskPortrait.
    3. Replace your previous UINavigationController with your new subclassed one.
    4. That's it. You're done!

    Because the default supported orientations for MPMoviePlayerViewController are "all but upside down", it will rotate as desired.
     
  5. straber, May 2, 2013
    Last edited: May 2, 2013

    straber thread starter macrumors member

    Joined:
    Jul 3, 2012
    #5
    OK, first off, thanks for your help, Dejo! In my case, the problem ended up being that one of my co-workers had added the method:

    Code:
    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        return UIInterfaceOrientationMaskPortrait;
    }
    to the app delegate. I'm not sure why he did this, but the important thing for anyone else with this problem to note is that adding this to your app delegate overrides the orientations you've selected in the summary tab of the project file.
     

Share This Page