我希望我的iPhone应用程序全局运行,就像只允许UIInterfaceOrientationPortrait一样。但同时,我希望它能够意识到物理方向,以便以特定的方式做出反应,仅在显示器的有限区域内。我怎么才能得到这个呢?
我使用UIViewController的self.interfaceOrientation iVar做了一些测试,但似乎不起作用,因为这个变量不会改变。
发布于 2013-06-20 13:04:18
首先,执行[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]。然后注册UIDeviceOrientationDidChangeNotification。收到通知后,请检查[UIDevice currentDevice].orientation以了解设备的物理方向。
您绝对应该阅读这些API的文档,因为其中包含一些重要的警告。
还要注意,设备方向是作为UIDeviceOrientation返回的,这与UIInterfaceOrientation不同。请记住UIInterfaceOrientation文档中的以下信息:
在statusBarOrientation属性和setStatusBarOrientation:animated:方法中使用这些常量。请注意,UIDeviceOrientationLandscapeRight被分配给UIInterfaceOrientationLandscapeLeft,UIDeviceOrientationLandscapeLeft被分配给UIInterfaceOrientationLandscapeRight;这样做的原因是旋转设备需要以相反的方向旋转内容。
https://stackoverflow.com/questions/17205495
复制相似问题