我想了解如何在iOS上检测设备的方向。我不需要接收更改通知,只需要当前的方向。这似乎是一个相当简单的问题,但我还没有能够理解它。以下是我迄今为止所做的:
UIDevice *myDevice = [UIDevice currentDevice] ;
[myDevice beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation deviceOrientation = myDevice.orientation;
BOOL isCurrentlyLandscapeView = UIDeviceOrientationIsLandscape(deviceOrientation);
[myDevice endGeneratingDeviceOrientationNotifications];
在我看来这应该可以工作。我启用了设备接收设备方向通知,然后询问它所处的方向,但它没有工作,我不知道原因。在我的想法里这应该有效。我将设备设置为接收设备方向通知,然后查询它的方向,但结果却不起作用,我不知道原因。