2014-10-29 96 views
1

我想强制视频全屏仅在横向上,我试过这个。但它不工作。应用程序的其余部分只有肖像。ios 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; 
} 

回答

0

你必须导入<MediaPlayer/MediaPlayer.h>和增加财产allowRotation和方法-(void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification和AppDelegate.h -(void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notification

相关问题