【问题标题】:Support all orientation only for video player view controller in a portrait application仅支持纵向应用程序中的视频播放器视图控制器的所有方向
【发布时间】:2016-10-24 03:17:28
【问题描述】:

我已经在 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 中启用自动旋转,但是当视频播放以横向模式结束时,整个应用程序只会转换为横向视图模式。

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

【问题讨论】:

标签: ios objective-c mpmovieplayercontroller


【解决方案1】:

仅当全屏模式演示发生或消失时,系统才会尝试使您的方向无效。所以我建议你用[self presentViewController:vc animated:YES completion:nil];替换你的[self.navigationController pushViewController:vc animated:false];

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多