在解除肖像时景观中的MPMoviePlayerViewController

时间:2014-07-16 19:49:09

标签: uitableview ios7 mpmovieplayercontroller

我有一个仅适用于PortraitMode的TableViewController。现在我想在触摸单元格时播放视频。 在我的App Delegate中,我正在使用该方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) {
    NSLog(@"ja1");
    return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[UINavigationController class]]) {
        NSLog(@"ja2");

        // look for it inside UINavigationController
        UINavigationController *nc = (UINavigationController *)[self.window.rootViewController presentedViewController];

        // is at the top?
        if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
            NSLog(@"ja3");
            return UIInterfaceOrientationMaskAllButUpsideDown;

            // or it's presented from the top?
        } else if ([[nc.topViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) {
            NSLog(@"ja4");
            return UIInterfaceOrientationMaskAllButUpsideDown;
        }
    }
}
return UIInterfaceOrientationMaskPortrait;
}

可以在观看视频时转向横向。

我从TableView

中显示了一个MPMoviePlayerViewController实例
- (void)playVideo {
NSURL *movieURL = [NSURL URLWithString:MYURL];
MPMoviePlayerViewController *c = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];

// Remove the movie player view controller from the "playback did finish" notification observers
[[NSNotificationCenter defaultCenter] removeObserver:c
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:c.moviePlayer];

// Register this class as an observer instead
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieFinishedCallback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:c.moviePlayer];

// Set the modal transition style of your choice
c.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

// Present the movie player view controller
[self presentViewController:c animated:YES completion:^{}];

// Start playback
[c.moviePlayer prepareToPlay];
[c.moviePlayer play];
}

现在我遇到了问题,当我在横向模式中关闭MPMoviePlayerViewController时,我想将其旋转回纵向模式。但我的MasterViewController(= TableView)仍处于横向模式。

你能救我一下吗?

1 个答案:

答案 0 :(得分:0)

在MasterViewController中实现以下方向方法。这将使您的MasterViewController保持纵向。

- (BOOL)shouldAutorotate{
    return false;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
// Returns interface orientation masks.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{  
    return UIInterfaceOrientationPortrait;
}
相关问题