iPhone - 屏幕旋转?
UIDeviceOrientation
为您提供有关物理设备本身的信息,同时UIInterfaceOrientation
告诉你的是显示视图的方向。这些不需要匹配;当用户使用方向锁或者设备方向朝上时。
您可能想要检查UIInterfaceOrientation
以及UIViewController
上的旋转方法以确定视图何时或应该旋转。
UIDeviceOrientation
指的是设备的物理方向,而UIInterfaceOrientation
指的是用户界面的方向。
因此,您需要设置的是autoResizeMask,以便在调整其超级视图的大小时正确调整视图的大小。为视图设置flexibleWidth和flexibleHeight。检查http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html
而且 - 是指
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]
你上面的代码是不正确的。您正在将设备方向分配给UIInterfaceOrientation变量。应该是'UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation],或者它应该是'UIInterfaceOrientation orientation = self.interfaceOrientation',其中self是UIViewController。 – mtmurdock
我希望在一年前知道的事情!我必须使用可以工作的设备方向来解决这个问题的整个解决方案,但是没有涵盖几个角落案例。小时的头痛......谢谢! – mtmurdock