【问题标题】:iPhone - Screen Rotation?iPhone - 屏幕旋转?
【发布时间】:2012-07-24 19:37:41
【问题描述】:

UIDeviceOrientationUIInterfaceOrientation 有什么区别?

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

【问题讨论】:

    标签: iphone ios uiinterfaceorientation uideviceorientation


    【解决方案1】:

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

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

    【讨论】:

    • 我希望我在一年前就知道的事情!我必须使用有效的设备方向来解决这个问题,但没有涵盖一些极端情况。头疼了好几个小时……谢谢!
    【解决方案2】:

    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]
    

    【讨论】:

    • 您上面的代码不正确。您正在将设备方向分配给 UIInterfaceOrientation 变量。应该是UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation] 或者应该是UIInterfaceOrientation orientation = self.interfaceOrientation,其中self 是一个UIViewController。
    猜你喜欢
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    相关资源
    最近更新 更多