首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode:收到警告"implicit conversion from enumeration type UIDeviceOrientation“

Xcode:收到警告"implicit conversion from enumeration type UIDeviceOrientation“
EN

Stack Overflow用户
提问于 2011-08-11 02:16:56
回答 1查看 21.4K关注 0票数 26

完整警告:

代码语言:javascript
复制
Implicit conversion from enumeration type 'UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation'

让它上线:

代码语言:javascript
复制
[self orientationChanged:interfaceOrientation];

方法如下:

代码语言:javascript
复制
- (void)orientationChanged:(UIInterfaceOrientation)interfaceOrientation 

我真的不能理解这个警告是从哪里来的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-11 02:22:59

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

代码语言:javascript
复制
[self orientationChanged:interfaceOrientation];

根据该方法,当您应该使用UIInterfaceOrientation时,您最有可能向它传递一个UIDeviceOrientation

在这一点上稍作扩展,UIDeviceOrientationUIDevice类的一个属性,可能有以下值:

UIDeviceOrientationUnknown -无法确定

UIDeviceOrientationPortrait -主视图按钮朝下

UIDeviceOrientationPortraitUpsideDown -主视图按钮朝上

UIDeviceOrientationLandscapeLeft -向右的主页按钮

UIDeviceOrientationLandscapeRight -向左的主页按钮

UIDeviceOrientationFaceUp -设备是扁平的,屏幕朝上

UIDeviceOrientationFaceDown -设备是扁平的,屏幕朝下

至于UIInterfaceOrientation,它是UIApplication的一个属性,并且只包含4种对应于状态栏方向的可能性:

代码语言:javascript
复制
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,

UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,

UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,

UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft

要获取UIDeviceOrientation,您可以使用

代码语言:javascript
复制
[[UIDevice currentDevice] orientation]

要获得UIInterfaceOrientation,您可以使用

代码语言:javascript
复制
[[UIApplication sharedApplication] statusBarOrientation] 
票数 97
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7015709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档