加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Xcode:获取警告“枚举类型的隐式转换UIDeviceOrientation”

发布时间:2020-12-15 02:04:14 所属栏目:百科 来源:网络整理
导读:全面警告: Implicit conversion from enumeration type 'UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation' 把它放在一起: [self orientationChanged:interfaceOrientation]; 这是方法: - (void)orientationChanged:(UIInter
全面警告:

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

把它放在一起:

[self orientationChanged:interfaceOrientation];

这是方法:

- (void)orientationChanged:(UIInterfaceOrientation)interfaceOrientation

我不知道这个警告来自哪里,我不是世界上最好的Xcoder,但我可以通过这个数字来确定。

任何帮助将不胜感激。

解决方法

UIDeviceOrientation是指设备的物理方向,而UIInterfaceOrientation是指用户界面的方向。当你打电话给你的方法

[self orientationChanged:interfaceOrientation];

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

只是为了扩展这一点,UIDeviceOrientation是UIDevice类的一个属性,并且有这些可能的值:

UIDeviceOrientationUnknown – Can’t be determined

UIDeviceOrientationPortrait – Home button facing down

UIDeviceOrientationPortraitUpsideDown – Home button facing up

UIDeviceOrientationLandscapeLeft – Home button facing right

UIDeviceOrientationLandscapeRight – Home button facing left

UIDeviceOrientationFaceUp – Device is flat,with screen facing up

UIDeviceOrientationFaceDown – Device is flat,with screen facing down

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

UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft

要获取UIDeviceOrientation,请使用

[[UIDevice currentDevice] orientation]

并获取UIInterfaceOrientation,您可以使用

[[UIApplication sharedApplication] statusBarOrientation]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读