【问题标题】:Rotate an iOS App ONLY When Playing a Video in WebKit?仅在 WebKit 中播放视频时旋转 iOS 应用程序?
【发布时间】:2023-06-10 18:51:01
【问题描述】:

我有一个 iOS 7 应用程序,我不希望整个界面是横向的,但是当用户播放视频时,我希望它以横向方式播放。我没有很多视图控制器,所以我可以在每个单独的控制器中实现一些东西。

【问题讨论】:

  • 请务必提供一些示例代码,以便人们能够更好地帮助您

标签: ios webkit uiinterfaceorientation


【解决方案1】:

您可以在视频播放时将视图强制为横向,然后在播放完毕后再次强制应用为纵向。

看看这个:force landscape ios 7

【讨论】:

    【解决方案2】:

    在某处添加此类别:

    @interface UINavigationController (rotation)
    
    @end
    
    @implementation UINavigationController (rotation)
    
    #pragma mark - Rotation
    
    - (BOOL)shouldAutorotate {
      return NO;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
      return UIInterfaceOrientationPortrait;
    }
    - (NSUInteger)supportedInterfaceOrientations {
      return UIInterfaceOrientationMaskPortrait;
    }
    
    // ios4 and ios5
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    @end
    

    【讨论】: