iPhone、iPad、苹果设备方向判断方法
2014-11-27 15:48
781 查看
在做项目的时候,我们经常要判断设备的方向,然后选择不同的图片。
现将判断设备方向的方法列举如下:
最常用的,一般的竖直方向,和按钮向右。因为玩游戏的话,基本是这两个方向。
但是记录数值,实在是太麻烦,如果我们直接能够判断具体方向的话,要比数值好一点。
现将判断设备方向的方法列举如下:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];//获取方向的方法 方向枚举如下: typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown, //对应数值为0 UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, //对应数值为1 UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, //对应数值为2 UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, //对应数值为3 UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft //对应数值为4 };
最常用的,一般的竖直方向,和按钮向右。因为玩游戏的话,基本是这两个方向。
但是记录数值,实在是太麻烦,如果我们直接能够判断具体方向的话,要比数值好一点。
if(UIInterfaceOrientationIsPortrait(orientation)) //判断设备方向是否是竖直,包括按钮朝下和按钮朝上两种情况。 #define UIInterfaceOrientationIsPortrait(orientation) ((orientation) == UIInterfaceOrientationPortrait || (orientation) == UIInterfaceOrientationPortraitUpsideDown) else if (UIInterfaceOrientationIsLandscape(orientation)) //此时设备的横着的 #define UIInterfaceOrientationIsLandscape(orientation) ((orientation) == UIInterfaceOrientationLandscapeLeft || (orientation) == UIInterfaceOrientationLandscapeRight)直接调用
if(UIInterfaceOrientationIsPortrait(orientation))和
else if (UIInterfaceOrientationIsLandscape(orientation))即可判定设备方向,将具体处理办法放入{}语句内。
相关文章推荐
- PHP简单判断iPhone、iPad、Android及PC设备的方法
- 检测iPhone/iPad设备方向的三种方法
- PHP判断iPhone、iPad、Android、PC设备的方法
- (iphone/ipad)一个简单的用代码判断当前设备的方法
- PHP判断iPhone、iPad、Android、PC设备的方法
- 三种检测iPhone/iPad设备方向的方法
- PHP判断iPhone、iPad、Android、PC设备的方法
- ios(iphone/ipad)一个简单的用代码判断当前设备的方法
- 三种检测iPhone/iPad设备方向的方法
- 判断用户设备是iPad还是iPhone的代码
- 在Cocoa里用objective-c判断设备类型:iPhone, iPod Touch, iPad
- ios判断设备是iphone还是ipad
- 如何判断 ios设备的类型(iphone,ipod,ipad)
- 判断设备的类型ipad或者iphone,调用自带应用,禁止锁屏,设置icon上的数字
- iphone开发 启动时判断设备方向
- 判断用户当前设备是iphone还是ipad
- 判断iphone ipad 设备上的相机是否可用
- iphone ipad等苹果设备30针数据线接口定义,大家可能有用
- ipad 判断设备的方向问题
- 判断用户设备是iPad还是iPhone的代码