xcode 从枚举类型“UIInterfaceOrientation”到不同枚举类型“UIDeviceOrientation”的隐式转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8413750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:41:53  来源:igfitidea点击:

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

iphoneobjective-cxcodesdkuideviceorientation

提问by GuybrushThreepwood

I am getting the above compiler warning for the code below. I understand the difference between Interface and Device orientation, but am unsure how to amend to remove the warning. Can anyone help ?

我收到以下代码的上述编译器警告。我了解界面和设备方向之间的区别,但不确定如何修改以删除警告。任何人都可以帮忙吗?

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (ViewController != NULL) {
    [ViewController configureForDeviceOrientation:toInterfaceOrientation];
}
if (Controller != NULL) {
    [Controller configureForDeviceOrientation:toInterfaceOrientation];
}
currentOrientation = toInterfaceOrientation;
}

回答by RolandasR

just cast it [Controller configureForDeviceOrientation:(UIDeviceOrientation)toInterfaceOrientation];

就投吧 [Controller configureForDeviceOrientation:(UIDeviceOrientation)toInterfaceOrientation];

回答by Luke

Your method configureForDeviceOrientation:is expecting to be passed a UIDeviceOrientationenum and not a UIInterfaceOrientationwhich you are passing in.

您的方法configureForDeviceOrientation:期望传递一个UIDeviceOrientation枚举而不是UIInterfaceOrientation您传入的一个。

If you correct your method to accept a UIInterfaceOrientationfrom the willRotateToInterfaceOrientation:method, then you'll resolve the issue.

如果你纠正你的方法接受一个UIInterfaceOrientationwillRotateToInterfaceOrientation:方法,那么你会解决这个问题。