1、对于iOS手机屏幕,苹果公司给出了一个枚举。
如:
typedef
NS_ENUM
(NSInteger, UIDeviceOrientation) {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait,
// 竖向,home键向下
UIDeviceOrientationPortraitUpsideDown,
//
竖向,home键向上
UIDeviceOrientationLandscapeLeft,
// 横
向,home键向右
UIDeviceOrientationLandscapeRight,
//
横
向,home键向左
UIDeviceOrientationFaceUp,
// 屏幕平放,向上
UIDeviceOrientationFaceDown
// 屏幕平放,向下
}
typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {
UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown,
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
}
2、对于获取手机屏幕
(1)
[[
UIDevice
currentDevice
]
beginGeneratingDeviceOrientationNotifications
];
dispatch_async
(
dispatch_get_main_queue
(), ^{
NSLog
(
@"=========%zd"
,[[
UIDevice
currentDevice
]
orientation
]);
});
[[
UIDevice
currentDevice
]
endGeneratingDeviceOrientationNotifications
];
(2)
UIInterfaceOrientation
orientation = [
UIApplication
sharedApplication
].
statusBarOrientation
;
3、对于当前手机是不是横屏或者竖屏的判断
(1)判断是否是竖屏
static
inline
BOOL
UIDeviceOrientationIsPortrait(
UIDeviceOrientation
orientation)
{
return
((orientation) ==
UIDeviceOrientationPortrait
|| (orientation) ==
UIDeviceOrientationPortraitUpsideDown
);
}
(2)判断是否是横屏
static
inline
BOOL
UIDeviceOrientationIsLandscape(
UIDeviceOrientation
orientation)
{
return
((orientation) ==
UIDeviceOrientationLandscapeLeft
|| (orientation) ==
UIDeviceOrientationLandscapeRight
);
}