单击iOS中的全屏按钮时,可以强制MPMoviePlayerController进行横向渲染

时间:2013-09-13 09:46:13

标签: ios objective-c cocoa-touch mpmovieplayercontroller

我在detailView(UIVIew)中创建了一个MPMoviePlayerController,现在我想在用户点击FullScreen按钮时强制MPMoviePlayerController进行横向视图。我能这样做吗?请给我任何建议。在此先感谢。这是我创建的代码:

   NSURL *movieURL = [NSURL URLWithString:previewString];
    movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    [movieController.view setFrame:CGRectMake(10,130, 275 , 150)];
    movieController.view.backgroundColor = [UIColor grayColor];
    [detailview addSubview:movieController.view];
    [movieController prepareToPlay];
    movieController.shouldAutoplay = NO;

和willEnterFullscreen()函数:

    - (void)willEnterFullscreen:(NSNotification*)notification {
    NSLog(@"willEnterFullscreen");
    donepress = YES;
    // nothing
}

我尝试过搜索,但仍然没有任何好的答案。请帮我。非常感谢

1 个答案:

答案 0 :(得分:12)

是的,您可以使用两个通知观察者来更改完整方向。

首先,在AppDelegate didFinishLaunchingWithOptions方法中添加两个通知观察器:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];

其次,添加方法和属性

- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = YES;
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = NO;
}

第三,覆盖supportedInterfaceOrientationsForWindow方法,你可以返回你想要的任何方向

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