Autorotate in iOS 6 has strange behaviour

2019-01-04 00:43发布

I have UITabBarController app which plays video and shows other information in other UITabBar tabs. In iOS 6 UIView rotation methods have been deprecated, and now I need to use shouldAutoRotate and supportedInterfaceOrientations methods. For video playing I use MPMoviePlayerViewController.

How to rotate only this player view? I can only rotate whole app, but don't want to do this. I present MPMoviePlayerViewController but it doesn't rotate as in iOS 5 and earlier.

In plist setting I've set only 1 Portrait interface orientation. If I set other - whole app will be rotated.

7条回答
爷、活的狠高调
2楼-- · 2019-01-04 01:37

I had the same problem with my app.

How the rotation in iOS 6 work is that.

=> when ever you are using UINavigationCOntroller the method in AppDelegate

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

decides whether to rotate or not.

=> when the view is presented in the Modal presentation style the method

- (BOOL)shouldAutorotate

which is inside the viewController for that view triggers the method in the appDelegate. And as 1st case appDelegate decides to rotate or not.

My Solution::

What I did for Modal presentation was that. Created a flag in app delegate.

when ever the flag is YES it rotates to Landscape and else its only Portrait.

- (NSUInteger)application:(UIApplication*)application
supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    if(self.shouldRotate ) //shouldRotate is my flag
    {
        self.shouldRotate = NO;
        return (UIInterfaceOrientationMaskAll);
    }
    return (UIInterfaceOrientationMaskPortrait);
}

And to toggle between rotations

- (BOOL)shouldAutorotate
{
    YourAppDelegate *mainDelegate = (YourAppDelegate*)[[UIApplication sharedApplication]delegate];
    mainDelegate.shouldRotate = YES;

    return YES;
}

Note: This works is only for view that are Modely Presented. Using Flag, not a good coding practice.

查看更多
登录 后发表回答