iOS 6 MPMoviePlayerViewController and presentMovie

2019-02-07 09:34发布

In previous iOS versions, our video would rotate automatically but in iOS 6 this is no longer the case. I know that the presentMoviePlayerViewControllerAnimated was designed to do that before but how can I tell the MPMoviePlayerViewController to rotate automatically?

MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];

4条回答
Lonely孤独者°
2楼-- · 2019-02-07 10:01

This is not limited to MPMoviePlayerViewController. From iOS 6 the autorotation has been changed. see Autorotate in iOS 6 has strange behaviour .

To make your app behave as pre-iOS 6, you have to make the app support all orientations (edit UISupportedInterfaceOrientations in plist), then for all other view controllers which don't support rotation, override this method to return NO:

- (BOOL)shouldAutorotate {
    return NO;
}

By default MPMoviePlayerViewController supports all orientations so this should be enough to make it work.

查看更多
爷、活的狠高调
3楼-- · 2019-02-07 10:06

I just ran into the same problem. James Chen's solution is correct, but I ended up doing something a little simpler that also works - overriding application:supportedInterfaceOrientationsForWindow in my app delegate and returning allButUpsideDown if my rootView controller was modally presenting an MPMoviePlayerViewController. Admittedly a hack, and may not be appropriate to all situations, but saved me having to change all my view controllers:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [rootViewController.modalViewController isKindOfClass:MPMoviePlayerViewController.class ] ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskAllButUpsideDown;
}
查看更多
倾城 Initia
4楼-- · 2019-02-07 10:14

In appdelegate.m :

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if ([[self.window.subviews.lastObject class].description isEqualToString:@"MPMovieView"]) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

Kinda a hack, but works well...

查看更多
做个烂人
5楼-- · 2019-02-07 10:16

I see there are lots of similar posts with app orientation in iOS 6. But in general, the solution is pretty simple: https://stackoverflow.com/a/13279778/691660

查看更多
登录 后发表回答