获取设备的方向

1.手机朝向的枚举

typedef NS_ENUM(NSInteger, UIDeviceOrientation) {

    UIDeviceOrientationUnknown,

    UIDeviceOrientationPortrait,            // 设备面向垂直,home 按钮在底部

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

    UIDeviceOrientationLandscapeLeft,       // 设备面向垂直,home 按钮在顶部

    UIDeviceOrientationLandscapeRight,      // 设备水平,面向 home 按钮在左边

    UIDeviceOrientationFaceUp,              // 设备平,面向脸了

    UIDeviceOrientationFaceDown             // 设备平,面向的脸

} __TVOS_PROHIBITED;

2.可以使用switch来记录设备的方向

获取设备方向的枚举值

[[UIDevice currentDevice] orientation]

switch ([[UIDevice currentDevice] orientation])

    {

        case UIDeviceOrientationPortraitUpsideDown:

            break;

        case UIDeviceOrientationLandscapeLeft:

            break;

        case UIDeviceOrientationLandscapeRight:

            break;

        case UIDeviceOrientationFaceUp:

        default:

            break;

    }

 

posted on 2017-01-04 10:41  敏言慎行  阅读(209)  评论(0编辑  收藏  举报

导航