How to get iPhones current orientation?

后端 未结 5 1495
忘掉有多难
忘掉有多难 2021-01-30 16:19

Is there a special method to get iPhones orientation? I don\'t need it in degrees or radians, I want it to return an UIInterfaceOrientation object. I just need it for an if-else

5条回答
  •  -上瘾入骨i
    2021-01-30 17:14

    This is most likely what you want:

    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    

    You can then use system macros like:

    if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
    {
    
    }
    

    If you want the device orientation use:

    UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
    

    This includes enumerations like UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown

提交回复
热议问题