How to get iPhones current orientation?

后端 未结 5 1584
忘掉有多难
忘掉有多难 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条回答
  •  无人共我
    2021-01-30 17:17

    With [UIApplication statusBarOrientation] being deprecated you should now use:

    UIWindowScene *activeWindow = (UIWindowScene *)[[[UIApplication sharedApplication] windows] firstObject];
    
    UIInterfaceOrientation orientation = [activeWindow interfaceOrientation] ?: UIInterfaceOrientationPortrait;
    

提交回复
热议问题