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

全面警告:

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]

相关文章

在有效期内的苹果开发者账号(类型为个人或者公司账号)。还...
Appuploader官网--IOS ipa上传发布工具,证书制作工具跨平台...
苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可...
计算机图形学--OpenGL递归实现光线追踪
Xcode 14打出来的包在低版本系统运行时会崩溃,报错信息是Li...