iPhone - 屏幕旋转?

问题描述:

UIDeviceOrientation & UIInterfaceOrientation有什么区别?iPhone - 屏幕旋转?

我应该使用哪一个来检测UIView上的旋转?

UIDeviceOrientation为您提供有关物理设备本身的信息,同时UIInterfaceOrientation告诉你的是显示视图的方向。这些不需要匹配;当用户使用方向锁或者设备方向朝上时。

您可能想要检查UIInterfaceOrientation以及UIViewController上的旋转方法以确定视图何时或应该旋转。

+1

我希望在一年前知道的事情!我必须使用可以工作的设备方向来解决这个问题的整个解决方案,但是没有涵盖几个角落案例。小时的头痛......谢谢! – mtmurdock

UIDeviceOrientation指的是设备的物理方向,而UIInterfaceOrientation指的是用户界面的方向。

因此,您需要设置的是autoResizeMask,以便在调整其超级视图的大小时正确调整视图的大小。为视图设置flexibleWidth和flexibleHeight。检查http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html

而且 - 是指

UIDEVICE orientation

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation] 
+0

你上面的代码是不正确的。您正在将设备方向分配给UIInterfaceOrientation变量。应该是'UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation],或者它应该是'UIInterfaceOrientation orientation = self.interfaceOrientation',其中self是UIViewController。 – mtmurdock