UIDevice currentDevice's “orientation” always null

后端 未结 5 1743
一生所求
一生所求 2020-12-18 00:23

As per the title. Calling [[UIDevice currentDevice] BeginGeneratingDeviceOrientationNotifications] has no effect.

DidRotateToInterfaceOrientation etc events are wor

5条回答
  •  伪装坚强ぢ
    2020-12-18 00:41

    UIDevice's notion of orientation seems to be only available on actual devices. The simulator seems to always return 0 here, regardless of whether the notifications have been enabled as the docs suggest. Irritatingly inconvenient, but there you go.

    I find this works fine on the actual device:

        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        NSLog(@"orientation: %d", [[UIDevice currentDevice] orientation]);
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    

提交回复
热议问题