来自枚举类型UIDeviceOrientation的隐式转换

来自枚举类型UIDeviceOrientation的隐式转换

本文介绍了Xcode:获得警告“来自枚举类型UIDeviceOrientation的隐式转换";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完整警告:

Implicit conversion from enumeration type 'UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation'

在线获取它:

[self orientationChanged:interfaceOrientation];

这是方法:

- (void)orientationChanged:(UIInterfaceOrientation)interfaceOrientation

我真的不明白这个警告是从哪里来的.

I can't really understand where this warning is coming from.

推荐答案

UIDeviceOrientation是指设备的物理方向,而UIInterfaceOrientation是指用户界面的方向.当您调用方法时

UIDeviceOrientation refers to the physical orientation of the device whereas UIInterfaceOrientation refers to the orientation of the user interface. When you call your method

[self orientationChanged:interfaceOrientation];

根据该方法,当您应该使用UIInterfaceOrientation时,很可能将其传递给UIDeviceOrientation.

you are most likely passing it a UIDeviceOrientation when you should, according to the method, be using a UIInterfaceOrientation.

仅在这一点上进行扩展,UIDeviceOrientationUIDevice类的属性,并且有以下可能的值:

Just to expand on this point a bit, UIDeviceOrientation is a property of the UIDevice class, and there are these possible values:

UIDeviceOrientationPortrait-主页按钮朝下

UIDeviceOrientationPortraitUpsideDown-主页按钮朝上

UIDeviceOrientationLandscapeLeft-向右的主页按钮

UIDeviceOrientationLandscapeRight-主页按钮向左

UIDeviceOrientationFaceUp-设备平坦,屏幕朝上

UIDeviceOrientationFaceUp - Device is flat, with screen facing up

UIDeviceOrientationFaceDown-设备平坦,屏幕朝下

UIDeviceOrientationFaceDown - Device is flat, with screen facing down

对于UIInterfaceOrientation,它是UIApplication的属性,仅包含与状态栏方向相对应的4种可能性:

As for UIInterfaceOrientation, it is a property of UIApplication and only contains 4 possibilities which correspond to the orientation of the status bar:

UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,

UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,

UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,

UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft

要获取UIDeviceOrientation,请使用

[[UIDevice currentDevice] orientation]

要获取UIInterfaceOrientation,请使用

[[UIApplication sharedApplication] statusBarOrientation]

这篇关于Xcode:获得警告“来自枚举类型UIDeviceOrientation的隐式转换";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:36