允许MPMoviePlayerViewController在横向播放,同时保留呈现视图控制器的方向

问题描述 投票:4回答:2

我正在用以下代码呈现MPMoviePlayerViewController(而不是XCDYouTubeVideoPlayerViewController的子类)>

LPVideo *video = [_videos objectAtIndex: indexPath.row];
XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier: video.code];
[self presentMoviePlayerViewControllerAnimated:videoPlayerViewController];

我的问题是,当整个应用程序都锁定为纵向模式时,我仍然希望用户以横向播放视频,因此将其放置在AppDelegate中

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
else
{
    return UIInterfaceOrientationMaskPortrait;
}
}

这在允许用户纵向观看视频时效果很好;但是,如果以纵向模式关闭视频播放器,则显示的视图控制器也已切换为纵向,这是我不希望发生的事情。

[我已经尝试了各种各样的方法,例如在主UINavigationController中实现supportedInterfaceOrientationsshouldAutorotate,但它甚至不能防止横向取向。

我知道这是有可能的,因为我已经看过应用程序可以这样做,但是我不知道如何做到。我已经看到了一些解决方案,其中包括听取方向更改并将转换应用于播放器视图,但这似乎不必要地复杂。

我也尝试通过viewWillAppear:animated返回时“强制”旋转,但是在调用代码时没有帮助。

我都尝试过这两个

UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window addSubview:view];

还有这个

[UIViewController attemptRotationToDeviceOrientation];

两者均无济于事。

我有一个MPMoviePlayerViewController(而不是XCDYouTubeVideoPlayerViewController的子类),我将使用以下代码LPVideo呈现* Video = [_videos objectAtIndex:indexPath.row]; ...

ios iphone objective-c uiviewcontroller orientation
2个回答
3
投票

问题尚不清楚,如果您想以所有方向播放视频,请使用“ UIInterfaceOrientationMaskAll”代替“ UIInterfaceOrientationMaskAllButUpsideDown”。如果不起作用,请检查您是否正在使用任何库,并更改方向。


8
投票

我通过检查isBeingDismissed解决了该问题:

© www.soinside.com 2019 - 2024. All rights reserved.