ios - 仅支持纵向应用程序中视频播放器 View Controller 的所有方向

标签 ios objective-c mpmovieplayercontroller

我已经在 AppDelegate.m 中实现了这段代码

-(UIInterfaceOrientationMask) application:(UIApplication *)application supportedInterfaceOrientationsForWindow :(UIWindow *)window
{
    UIViewController *currentVC = [(UINavigationController *)[UIApplication sharedApplication].delegate.window.rootViewController topViewController];
    if ([currentVC isKindOfClass:[VideoPlayerVC class]])
    {
        return UIInterfaceOrientationMaskAll;
    }

    return UIInterfaceOrientationMaskPortrait;
}

并使用这样的链接推送到 VideoPlayerVC :

NSURL *link = [NSURL URLWithString:strUrl];
VideoPlayerVC *vc = [[VideoPlayerVC alloc] init];
vc.videoUrl = link;
[self.navigationController pushViewController:vc animated:false];

这允许我在 VideoPlayer ViewController 中启用自动旋转,但是当视频播放以横向模式结束时,整个应用程序将仅转换为横向 View 模式。

请帮我解决这个问题。 提前致谢。

最佳答案

系统只会在全屏模式演示发生或关闭时尝试使您的方向无效。所以我建议您将 [self.navigationController pushViewController:vc animated:false]; 替换为 [self presentViewController:vc animated:YES completion:nil];

如果您的 UE 需要导航转换,您可以尝试使用 UIViewControllerContextTransitioning 自定义来模仿它。

如果你必须使用推送行为,还有一个棘手的方法(据我所知,这是唯一一种不使用私有(private) api 的方法) 每次从导航堆栈中推送/弹出时,调用以下代码: [[vc presentViewController:[UIViewController new] animated:NO completion:^(BOOL completed){ [vc dismissViewControllerAnimated:没有完成:无]; }]; 该代码尝试制作一个不可见的 vc 并立即关闭它以使 iOS 更新支持的方向。

关于ios - 仅支持纵向应用程序中视频播放器 View Controller 的所有方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37963655/

相关文章:

iOS 7 3. 5"vs 4"将内容移出屏幕

objective-c - 为什么 MPMoviePlayerController 没有暂停?

iphone - MpMovieplayer 在提醒警报弹出期间崩溃

ios - 如何在首次启动时仅显示一次 UIPageViewController

android - 通过蓝牙控制智能 watch

iphone - 使用 GCD 的读写锁

php - 通过 POST 将 NSMutableArray 传递给 PHP

iphone - MPMoviePlayerController 上的专辑封面

ios - 如果在 iOS7 中后台运行 cocos2d 2.1 应用程序同时观看 Game Center 屏幕(排行榜、成就)会崩溃

ios - xcode更新从不同分支构建的PCH文件后出现问题