首页 文章

修复横向模式下的旋转问题

提问于
浏览
1

我有一个使用AVCapturesession捕获图像的应用程序,我有一个内置UIView的View Controller,我在这个视图中运行会话 .

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

唯一的问题是,当我的应用程序以横向模式打开时,它不是全屏幕,一旦我将其旋转为肖像,它将全屏显示,然后在回到横向时它仍然是全屏 .

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

1 回答

  • 0

    我遇到了同样的问题 . 你应该在app delegate类中实现这个方法 . 这是一个例子 . 希望你能得到这个 .

    - (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
    

相关问题