• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 关闭 MPMoviePlayerViewController 后自动旋转 ViewController

[复制链接]
菜鸟教程小白 发表于 2022-12-12 19:17:46 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

在您否决这个问题之前,请注意,我已经尝试实现 stackoverflow 上的所有可用解决方案。问题来了:

我的应用程序仅在纵向模式下运行。唯一需要横向的是视频播放器。当用户点击我的 TableViewCell 时,会调用此代码块:

    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoUrl];
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];

之后,我需要让用户能够以纵向和横向模式观看视频。完成后,一切都应该回到纵向模式。我试图在我的 AppDelegate.m 中调用这段代码:

- (NSUInteger) applicationUIApplication *)application supportedInterfaceOrientationsForWindowUIWindow *)window
{
    NSUInteger orientations = UIInterfaceOrientationMaskPortrait;

    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) {
        orientations = UIInterfaceOrientationMaskAllButUpsideDown;
    }

    return orientations;
}

有了它,一切都很好,除了一件事 - 当视频结束或用户在横向模式下点击 “完成” 按钮时,我的 View Controller 也会以横向模式出现。

除此之外,我尝试了很多其他方法 - 但似乎没有任何效果。

我会很高兴得到任何帮助!



Best Answer-推荐答案


感谢@Shubham - Systematix 提供 the answer .

我所要做的就是删除所有与自动旋转相关的代码,除了 AppDelegate 中的这个方法:

- (NSUInteger) applicationUIApplication *)application supportedInterfaceOrientationsForWindowUIWindow *)window {
    if ([[window.rootViewController presentedViewController] isKindOfClass:        [MPMoviePlayerViewController class]])
    {
        //NSLog(@"in if part");
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        //NSLog(@"in else part");
        return UIInterfaceOrientationMaskPortrait;
    }
}

当我这样做时,一切都像魔术一样!

关于ios - 关闭 MPMoviePlayerViewController 后自动旋转 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21991255/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap