警告:从枚举类型'UIInterfaceOrientation'到不同的枚举类型'UIDeviceOrientation'的隐式转换?

时间:2011-10-19 00:39:50

标签: warnings uiinterfaceorientation implicit xcode4.2 uideviceorientation

在这一行:[self deviceInterfaceOrientationChanged:interfaceOrientation];

我收到此警告

Implicit conversion from enumeration type ' UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation'?
你可以帮帮我吗?谢谢你

以下是代码:

     -(void) receivedRotate: (NSNotification*) notification
{
    NSLog(@"receivedRotate");
    UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

    if(interfaceOrientation != UIDeviceOrientationUnknown) {
        [self deviceInterfaceOrientationChanged:interfaceOrientation];


    } else {
        NSLog(@"Unknown device orientation");
    }
}

1 个答案:

答案 0 :(得分:0)

UIDeviceOrientation和UIInterfaceOrientation是不同的类型,第一个是设备方向,包括其他状态,如Face up或Face Down等,而第二个只覆盖2D状态,如Portrait和Landscape。

不要从设备获取设备方向,而是从状态栏获取,如下所示:

[[UIApplication sharedApplication] statusBarOrientation] 

此方法将返回UIInterfaceOrientation值,问题将消失。

相关问题