在iOS 10之前,有两个通知 MPMoviePlayerWillEnterFullscreenNotification和MPMoviePlayerWillExitFullscreenNotification 让观察者进入全屏模式,但是在iOS 10中不推荐通知,那么如何在设备旋转时更改 UIInterfaceOrientationMask?
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[self.window.rootViewController presentedViewController]
isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
if ([[self.window.rootViewController presentedViewController]
isKindOfClass:[UINavigationController class]]) {
// look for it inside UINavigationController
UINavigationController *nc = (UINavigationController *)[self.window.rootViewController presentedViewController];
// is at the top?
if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
// or it's presented from the top?
} else if ([[nc.topViewController presentedViewController]
isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)