"interfaceOrientation";在iOS 8中已弃用,如何更改此方法Objective C [英] "interfaceOrientation" is deprecated in iOS 8, How to change this method 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屋!