使用仅肖像应用程序允许在横向上播放视频

我有一个包含在UIViewController中的UIWebView,它是UINavigationController的后代。看起来像这样:

主视图

该应用程序仅是纵向的。播放视频时,我希望用户能够旋转设备并以横向模式观看视频。我使用此代码允许它:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    id presentedViewController = [self topMostController];
    NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;

    if ([className isEqualToString:@"MPInlineVideoFullscreenViewController"] ||
        [className isEqualToString:@"MPMoviePlayerViewController"] ||
        [className isEqualToString:@"AVFullScreenViewController"]) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }

    return UIInterfaceOrientationMaskPortrait;
}

- (UIViewController *)topMostController {
    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;

    while (topController.presentedViewController) {
        topController = topController.presentedViewController;
    }

    return topController;
}

然后在我的UINavigationController中(因此,当视频结束时,视图不是以横向呈现,而是以纵向呈现):

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

一切正常:

录像肖像 视频风景

但是随后视频播放完毕(或用户点击“完成”),屏幕返回到基础视图,这是发生的情况:

导航栏问题

As you can see, the navigation bar slips under the status bar. Additionally, I get a lot of auto-layout errors in the logs: http://pastebin.com/09xHzmgJ

Any idea about how to solve this?

entropid

I temporarily solved (through a hack) with the following code in the viewDidLoad of my controller. I have to specify that the code is specifically made for my case: since I explicitly disallow landscape orientation of my UINavigationController (see code above), the usual notification “UIDeviceOrientationDidChange” is not called when the playback finished and the window goes back to portrait. However, I hope there is a better option and this is a bug of the SDK, since it does not appear on iOS 7 and given the amount of auto-layout errors I get related to the video player (on which I have no control).

- (void)viewDidLoad
{
    [super viewDidLoad];

    // […]

     /* 
     Hack to fix navigation bar position/height on iOS 8 after closing fullscreen video

     Observe for “UIWindowDidRotateNotification” since “UIDeviceOrientationDidChangeNotification” is not called in the present conditions
     Check if the notification key (“UIWindowOldOrientationUserInfoKey”) in userInfo is either 3 or 4, which means the old orientation was landscape
     If so, correct the frame of the navigation bar to the proper size.

     */
    [[NSNotificationCenter defaultCenter] addObserverForName:@"UIWindowDidRotateNotification" object:nil queue:nil usingBlock:^(NSNotification *note) {
        if ([note.userInfo[@"UIWindowOldOrientationUserInfoKey"] intValue] >= 3) {
            self.navigationController.navigationBar.frame = (CGRect){0, 0, self.view.frame.size.width, 64};
        }
    }];
}

接着…

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:@"UIWindowDidRotateNotification"];
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

当我的整个应用程序处于纵向模式时,以横向模式全屏播放视频

来自分类Dev

从横向启动应用程序时在IOS中锁定肖像方向

来自分类Dev

播放视频时应用程序崩溃

来自分类Dev

在“仅肖像”应用中以横向模式显示UIViewController

来自分类Dev

如何创建仅横向视图的ios应用程序

来自分类Dev

在将设备保持为横向模式的情况下打开应用程序时,在“肖像”活动对话框中显示横向方向

来自分类Dev

仅在android API级别8中的横向上播放视频

来自分类Dev

使用应用程序图标向上导航

来自分类Dev

无法使用Phonegap应用程序在IOS 9中播放本地视频

来自分类Dev

我如何使用wkwebview在我的应用程序中自动播放视频

来自分类Dev

使用AVPlayer在macOS SwiftUI应用程序中播放本地视频文件

来自分类Dev

gstreamer 出现问题,在 Ubuntu 上使用 qt 5.10 应用程序播放视频

来自分类Dev

哪个是使用目标 sdk 26 在 Android 应用程序上播放 RTSP 视频的最佳 API?

来自分类Dev

在ruby on rails应用程序中播放视频

来自分类Dev

如何在余烬应用程序中播放YouTube视频

来自分类Dev

youtube视频无法在我的webview应用程序中播放?

来自分类Dev

如何从Android中的应用程序缓存播放视频

来自分类Dev

在C#桌面应用程序中播放视频

来自分类Dev

youtube视频无法在我的webview应用程序中播放?

来自分类Dev

同时在QT应用程序上播放多个视频

来自分类Dev

在Android应用程序中播放视频时出错

来自分类Dev

开发 Andriod 应用程序以列出视频并选择播放

来自分类Dev

关闭android应用程序时如何播放视频

来自分类Dev

使用本机脚本framewok流视频并在我的移动应用程序中播放,其中包括对视频上传的支持

来自分类Dev

为什么我的Android应用程序中的“图像选择器”会自动将肖像图像旋转为横向图像?

来自分类Dev

为什么我的Android应用程序中的“图像选择器”会自动将肖像图像旋转为横向图像?

来自分类Dev

iptables / pf规则仅允许XY应用程序/用户使用?

来自分类Dev

当开始/停止使用设备的相机应用程序中听到的AVCaptureMovieFileOutput录制视频时播放相同的声音吗?

来自分类Dev

当我的应用程序最小化时,使用Android中的Youtube API播放音乐视频中的音频

Related 相关文章

  1. 1

    当我的整个应用程序处于纵向模式时,以横向模式全屏播放视频

  2. 2

    从横向启动应用程序时在IOS中锁定肖像方向

  3. 3

    播放视频时应用程序崩溃

  4. 4

    在“仅肖像”应用中以横向模式显示UIViewController

  5. 5

    如何创建仅横向视图的ios应用程序

  6. 6

    在将设备保持为横向模式的情况下打开应用程序时,在“肖像”活动对话框中显示横向方向

  7. 7

    仅在android API级别8中的横向上播放视频

  8. 8

    使用应用程序图标向上导航

  9. 9

    无法使用Phonegap应用程序在IOS 9中播放本地视频

  10. 10

    我如何使用wkwebview在我的应用程序中自动播放视频

  11. 11

    使用AVPlayer在macOS SwiftUI应用程序中播放本地视频文件

  12. 12

    gstreamer 出现问题,在 Ubuntu 上使用 qt 5.10 应用程序播放视频

  13. 13

    哪个是使用目标 sdk 26 在 Android 应用程序上播放 RTSP 视频的最佳 API?

  14. 14

    在ruby on rails应用程序中播放视频

  15. 15

    如何在余烬应用程序中播放YouTube视频

  16. 16

    youtube视频无法在我的webview应用程序中播放?

  17. 17

    如何从Android中的应用程序缓存播放视频

  18. 18

    在C#桌面应用程序中播放视频

  19. 19

    youtube视频无法在我的webview应用程序中播放?

  20. 20

    同时在QT应用程序上播放多个视频

  21. 21

    在Android应用程序中播放视频时出错

  22. 22

    开发 Andriod 应用程序以列出视频并选择播放

  23. 23

    关闭android应用程序时如何播放视频

  24. 24

    使用本机脚本framewok流视频并在我的移动应用程序中播放,其中包括对视频上传的支持

  25. 25

    为什么我的Android应用程序中的“图像选择器”会自动将肖像图像旋转为横向图像?

  26. 26

    为什么我的Android应用程序中的“图像选择器”会自动将肖像图像旋转为横向图像?

  27. 27

    iptables / pf规则仅允许XY应用程序/用户使用?

  28. 28

    当开始/停止使用设备的相机应用程序中听到的AVCaptureMovieFileOutput录制视频时播放相同的声音吗?

  29. 29

    当我的应用程序最小化时,使用Android中的Youtube API播放音乐视频中的音频

热门标签

归档