ios MPMoviePlayerController强制横向全屏

时间:2014-10-29 18:25:10

标签: ios objective-c mpmovieplayercontroller

我想强制视频全屏只在风景上,我试过这个。但它不起作用。应用程序的其余部分只有肖像。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
Second, Add the method and property

- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = YES;
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = NO;
}
Third, override the supportedInterfaceOrientationsForWindow method, you can return whatever orientation you want

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (self.allowRotation) {
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    return UIInterfaceOrientationMaskPortrait;
}

1 个答案:

答案 0 :(得分:0)

您必须导入<MediaPlayer/MediaPlayer.h>并添加属性allowRotation和方法-(void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification和 AppDelegate.h中的-(void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notification