UIDevice currentDevice的“方向”总是空的 [英] UIDevice currentDevice's "orientation" always null
问题描述
根据标题。
调用[[UIDevice currentDevice] BeginGeneratingDeviceOrientationNotifications]无效。
As per the title. Calling [[UIDevice currentDevice] BeginGeneratingDeviceOrientationNotifications] has no effect.
DidRotateToInterfaceOrientation等事件工作正常,但我需要能够任意轮询设备方向。
DidRotateToInterfaceOrientation etc events are working fine, but I need to be able to poll the device orientation arbitrarily.
如何修复/执行此操作?
How can I fix/do this?
长篇故事:
我有一个每个选项卡上带有导航控制器的选项卡应用第一个选项卡的根视图是当方向变为横向时全屏显示的图形;然而,每当视图出现时都需要检查,因为方向改变可能在其他地方发生,所以我希望每当这个视图出现时轮询方向状态。
The long story: I have a tab application with a navigation controller on each tab. The root view of tab number one is a graph that goes full screen when the orientation changes to landscape; however this needs to be checked whenever the view appears as the orientation change could have occurred elsewhere, so I was hoping to poll the orientation state whenever this view appears.
推荐答案
UIDevice的方向概念似乎只能在实际设备上使用。无论是否已按照文档建议启用通知,模拟器似乎总是在此处返回0。非常不方便,但你去了。
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];
这篇关于UIDevice currentDevice的“方向”总是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!