gpt4 book ai didi

objective-c - Xcode:收到警告 "implicit conversion from enumeration type UIDeviceOrientation"

转载 作者:太空狗 更新时间:2023-10-30 03:11:19 25 4
gpt4 key购买 nike

完整警告:

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

上线:

[self orientationChanged:interfaceOrientation];

这是方法:

- (void)orientationChanged:(UIInterfaceOrientation)interfaceOrientation 

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

最佳答案

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

[self orientationChanged:interfaceOrientation];

根据方法,当您应该使用 UIInterfaceOrientation 时,您很可能向它传递了 UIDeviceOrientation

只是稍微扩展一下这一点,UIDeviceOrientationUIDevice 类的一个属性,并且有这些可能的值:

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] 

关于objective-c - Xcode:收到警告 "implicit conversion from enumeration type UIDeviceOrientation",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7015709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com