您的位置:首页 > 产品设计 > UI/UE

UIDeviceOrientation & UIInterfaceOrientation & UIInterfaceOrientationMask

2020-05-11 04:07 956 查看

1、UIDeviceOrientation

UIDeviceOrientation的定义在UIDevice.h中,它的定义如下:

//  UIDevice.h

... 

typedef NS_ENUM(NSInteger, UIDeviceOrientation) {

    UIDeviceOrientationUnknown,

    UIDeviceOrientationPortrait,               // Device oriented vertically, home button on the bottom

    UIDeviceOrientationPortraitUpsideDown,     // Device oriented vertically, home button on the top  

    UIDeviceOrientationLandscapeLeft,            // Device oriented horizontally, home button on the right

    UIDeviceOrientationLandscapeRight,         // Device oriented horizontally, home button on the left

    UIDeviceOrientationFaceUp,                     // Device oriented flat, face up 

    UIDeviceOrientationFaceDown                  // Device oriented flat, face down

};

由此可见,设备方向有7种,这是一个三维的方向体系,每个方向一种,再加上一种不可判断的。

人为判断设备方向的方法:通过home按钮定位。注意:设备方向左时home按钮在右边,设备方向右时home按钮在左边。

程序获取设备方向的方法是:[[UIDevicecurrentDevice] orientation]

 

2、UIInterfaceOrientation 

UIInterfaceOrientation的定义在UIApplication.h中,它的定义如下:

//

//  UIApplication.h

...

// Note that UIInterfaceOrientationLandscapeLeft is equal to UIDeviceOrientationLandscapeRight (and vice versa).

// This is because rotating the device to the left requires rotating the content to the right.

typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {

    UIInterfaceOrientationPortrait               = UIDeviceOrientationPortrait,

    UIInterfaceOrientationPortraitUpsideDown   = UIDeviceOrientationPortraitUpsideDown,

    UIInterfaceOrientationLandscapeLeft            = UIDeviceOrientationLandscapeRight,

    UIInterfaceOrientationLandscapeRight          = UIDeviceOrientationLandscapeLeft

};

由此可见,界面方向是二维的,界面方向的左和右跟home按钮的左右相同。

人工判断界面方向的方法是:木有方法判断界面方向,界面方向取决于程序实现。

程序获取界面方向的方法是:[[UIApplicationsharedApplication] statusBarOrientation]

 

3.UIInterfaceOrientationMask

UIInterfaceOrientation的定义在UIApplication.h中,它的定义如下:

//

//  UIApplication.h

...

typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) {

    UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),

    UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),

    UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),

    UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),

    UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),

    UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),

    UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),

};

由UIInterfaceOrientationMask的名称可以知道,它只是为了支持多种UIInterfaceOrientation而定义的类型。

它跟UIViewController相关,在UIViewController中可以通过[self supportedInterfaceOrientations]获取支持的UIInterfaceOrientation。

 

转载于:https://www.cnblogs.com/StarMud/archive/2012/11/01/2749866.html

a2614555 原创文章 0获赞 0访问量 211 关注 私信
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐