我已经在 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/