5

A Question was asked earlier. And i was facing the same issue where the Movie player was not rotating as the project properties didn't allowed to rotate. This issue was only faced in iOS7 over iPhone so i am trying another work around where i enable all the orientation in project Properties but the issue is that when ever i disable the rotation in other view controllers through functions like this

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
     return FALSE;
}

// Tell the system what we support
-(NSUInteger)supportedInterfaceOrientations
 {
return UIInterfaceOrientationPortrait;
}

- (BOOL) shouldAutorotate {
return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;

}

The view controllers still rotate which i suppose that this is because its allowed in project properties.

So the Question is..

How can i disable Rotation in a specific Media Player View Controller when Project settings allows all rotation?

OR

How can i Override rotation in a specific Media Player view controller over project properties (Disabling rotation) which doesn't work in iOS7

Community
  • 1
  • 1

2 Answers2

8

you can implement below method in you AppDelegate class it's working for me:

 - (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    if ([[window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        return UIInterfaceOrientationMaskPortrait;
    }
}
Shubham
  • 570
  • 3
  • 12
  • 1
    Your answer is correct and i am really thankful to you for that.. but there is one issue which i would like you to help me. Which is that when i click done on the Media Player my previous ViewController is in landscape mode which is a problem. How can i resolve that? –  Jan 15 '14 at 10:22
  • you need to manage this inside the -(void)myMovieFinishedCallback:(NSNotification*)aNotification – Shubham Jan 15 '14 at 10:27
  • Thanks .. Some upvotes for you.. More coming if i needed more help. Coz you saved half of my day. thanks Again –  Jan 15 '14 at 10:39
  • Btw i do have this notification setup but still no idea what should i set. although i did called '[self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait]; [self willRotateToInterfaceOrientation:UIInterfaceOrientationPortrait duration:0.0];' on previous controller's 'viewWillAppear' –  Jan 15 '14 at 10:42
  • So what should i set in the PlayerFinished Notification? –  Jan 15 '14 at 10:55
  • remove all other orientation method from view controller which you have mentioned me above that you have added some code in viewWillAppear. – Shubham Jan 15 '14 at 11:16
  • Hey I'm getting [window.rootViewController presentedViewController] and [window.rootViewController presentingViewController] both nil. – nikhil84 Sep 17 '14 at 04:46
  • Didn't work for me, rotation still working. – ScottyBlades Jun 11 '21 at 02:39
0

When we are talking about orientation, they are 2 things that come into the picture:

Device Orientation Interface Orientation As its clear by the name only, Device orientation tells, in which orientation device is, and Interface orientation says in which orientation your app is presenting its interface.

Here what you are doing is, your app is supporting all orientation. You must have check marked all orientations in project.

Now when you are changing orientation of device from portrait to landscape, when you have set interfaceOrientation to be in portrait mode programmatically, this is what happens. As device orientation is changes, orientation of your status bar also changes. But as you have restricted interface of your app to be in portrait orientation, its not changing its orientation..

So this is what you can do:

Uncheck landscape orientation support for your app & check if problem persists. Let me know what happened when you followed first step :)

Prince Agrawal
  • 3,619
  • 3
  • 26
  • 41