"interfaceOrientation";在iOS 8中已弃用,如何更改此方法Objective C [英] "interfaceOrientation" is deprecated in iOS 8, How to change this method Objective C

查看:454
本文介绍了"interfaceOrientation";在iOS 8中已弃用,如何更改此方法Objective C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从可可控件下载了一个使用此方法的simpleCamera视图

I have downloaded a simpleCamera view from Cocoa Controls which use this method

- (AVCaptureVideoOrientation)orientationForConnection
{
    AVCaptureVideoOrientation videoOrientation = AVCaptureVideoOrientationPortrait;
    switch (self.interfaceOrientation) {
        case UIInterfaceOrientationLandscapeLeft:
            videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
            break;
        case UIInterfaceOrientationLandscapeRight:
            videoOrientation = AVCaptureVideoOrientationLandscapeRight;
            break;
        case UIInterfaceOrientationPortraitUpsideDown:
            videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
            break;
        default:
            videoOrientation = AVCaptureVideoOrientationPortrait;
            break;
    }
    return videoOrientation;
}

问题是iOS 8中不推荐使用"interfaceOrientation",但我不知道在Switch状态下该如何以及如何替换它.

the problem is "interfaceOrientation" deprecated in iOS 8 but i dont know what and how to replace this in Switch condition.

推荐答案

获取设备方向不正确.例如,设备可能处于横向模式,但是仅支持纵向模式的视图控制器将保持纵向模式.

Getting the device orientation is not correct. For instance, the device might be in landscape mode, but a view controller that only supports portrait will remain in portrait.

相反,请使用:

[[UIApplication sharedApplication] statusBarOrientation]

另一个好处是它仍然使用UIInterfaceOrientation枚举,因此几乎不需要更改代码.

Another bonus is that it still uses the UIInterfaceOrientation enum, so very little of your code needs to change.

这篇关于"interfaceOrientation";在iOS 8中已弃用,如何更改此方法Objective C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆