【问题标题】:Fix rotation issue in landscape mode修复横向模式下的旋转问题
【发布时间】:2016-03-31 08:31:51
【问题描述】:

我有一个使用 AVCapturesession 捕获图像的应用程序,我有一个视图控制器,里面有一个 UIView,我在这个视图中运行会话。

当我的应用程序以纵向模式加载时,一切都很好,它会打开全屏并在旋转到横向模式时也保持全屏,因为我的视图用于捕获图像,所以我不允许仅旋转 UIView捕捉图像一切正常。

唯一的问题是,当我的应用以横向模式打开时,它不是全屏的,一旦我将其旋转到纵向,它就会变成全屏,然后回到横向时它仍然是全屏。

我该如何解决这个问题,或者有没有办法强制您的 iOS 应用始终以纵向模式打开,然后让它旋转?

【问题讨论】:

    标签: ios objective-c uiview avcapturesession landscape-portrait


    【解决方案1】:

    我遇到了同样的问题。你应该在你的应用委托类中实现这个方法。这是示例。希望这是您所需要的。

    - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
    {
        if([window.rootViewController isKindOfClass:[HRMHomeViewController class]])
        {
            id homeViewController = (HRMHomeViewController*)window.rootViewController;
            if ([[homeViewController presentedViewController]
                 isKindOfClass:[HRMCapturedScreenViewController class]])
                return UIInterfaceOrientationMaskPortrait;
        }
        return UIInterfaceOrientationMaskAll;
    }
    

    使用此方法,您的相机层的框架将根据方向旋转

    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                             duration:(NSTimeInterval)duration
    {
        [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation
                                                duration:duration];
        self.captureManager.cameraLayer.frame = self.videoView.bounds;
    }
    

    UINavigationController 中有一些方法可以提供帮助。这里有两种方法,或者创建 UINavigationController 的类别或继承它。

    - (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController 
    - (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      相关资源
      最近更新 更多