【问题标题】:how can i set landscape orientation when playing a video from webview从 webview 播放视频时如何设置横向
【发布时间】:2015-02-11 22:16:54
【问题描述】:

我有一个带有视频链接的 web 视图,该应用程序只有纵向,但当视频全屏并使用全屏时,我需要更改方向。 感谢您的帮助。

【问题讨论】:

标签: ios objective-c uiwebview orientation


【解决方案1】:

把这个放在你的AppDelegate:

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    id presentedViewController = [window.rootViewController presentedViewController];
    NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;

    if (window && [className isEqualToString:@"AVFullScreenViewController"]) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

注意:我没有在 iOS7 上对此进行了测试,但在 iOS8 上运行良好

【讨论】:

  • 方法签名不正确 - 应该返回 UIInterfaceOrientationMask 而不是 NSUInteger。从技术上讲,它是一样的,但我认为 Xcode 会抱怨。
  • 我不明白@MichaelCueno 这是基于 Apple 3 操作系统之前提供的文档的答案。我不能说你所说的是正确还是不正确,因为我已经有一年多没有看过文档了,因为我正处于工作和旅行之间的间隙。我敢肯定苹果已经弃用了很多东西。如果你对 iOS ≥10 有更好的答案,请提供给其他人看,通常 cmet 不会引起人们的注意。收到此通知的人让我想念它:/
  • 我认为@Michael Cueno 的意思是,在 XCode 8 中,IDE 会抱怨返回值应该是 UIInterfaceOrientationMask,而不是 NSUInteger
  • 这是解决此问题的最佳且简单的解决方案!干得好!
【解决方案2】:

除了this answer 用于 iOS 7 和 iOS 8

放入 AppDelegate。适用于 iOS 7 和 iOS 8:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    id presentedViewController = [window.rootViewController presentedViewController];
    NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;


    if (window && ([className isEqualToString:@"MPInlineVideoFullscreenViewController"] || [className isEqualToString:@"AVFullScreenViewController"])) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多