5

我在 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
}

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

4

1 回答 1

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;
}
于 2013-10-15T03:31:19.153 回答