ios开发之确定设备当前的方向
来源:互联网 发布:学生网络兼职打字员 编辑:程序博客网 时间:2024/05/22 17:58
有时候我们需要判断应用程序当前的方向,可以通过获取设备当前的方向来确定,从下面的定义你可以看到UIInterfaceOrientation的定义是通过UIDeviceOrientation来完成的,有两个概念:
UIDeviceOrientation:硬件设备的方向
UIInterfaceOrientation:应用程序界面的方向
UIDeviceOrientation的定义如下:
typedef enum { 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} UIDeviceOrientation;
UIInterfaceOrientation的定义如下:
typedef enum { UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft} UIInterfaceOrientation;
可采用下面的方式来判断当前设备的方向:
UIDevice *device = [UIDevice currentDevice];switch (device.orientation) { case UIDeviceOrientationUnknown: NSLog(@"Unknown"); break; case UIDeviceOrientationFaceUp: NSLog(@"Device oriented flat, face up"); break; case UIDeviceOrientationFaceDown: NSLog(@"Device oriented flat, face down"); break; case UIDeviceOrientationLandscapeLeft: NSLog(@"Device oriented horizontally, home button on the right"); break; case UIDeviceOrientationLandscapeRight: NSLog(@"Device oriented horizontally, home button on the left"); break; case UIDeviceOrientationPortrait: NSLog(@"Device oriented vertically, home button on the bottom"); break; case UIDeviceOrientationPortraitUpsideDown: NSLog(@"Device oriented vertically, home button on the top"); break; default: NSLog(@"cannot distinguish"); break; }
或者是:
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIsLandscape(deviceOrientation)) NSLog(@"The orientation is landscape"); else if(UIDeviceOrientationIsPortrait(deviceOrientation)) NSLog(@"The orientation is portrait");
UIDeviceOrientationIsLandscape的定义如下:
#define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)
UIDeviceOrientationIsPortrait的定义如下:
#define UIDeviceOrientationIsPortrait(orientation) ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown)
有时候我们只需要知道当前设备是水平还是竖直放置,就可以采用第二种方法。
- ios开发之确定设备当前的方向
- IOS判断设备当前的方向
- ios开发之--判断当前设备的类型
- ios开发之--判断当前设备的类型
- iOS判断当前设备旋转方向
- ios开发屏幕旋转锁定时判断设备的方向
- ios 获得设备的方向
- (0035) iOS 开发之获得当前设备的IP(分IPv4 & IPv6)
- iOS中检测当前设备的旋转方向(关闭屏幕旋转)
- [ios]ios开发之检测UIScrollView的滚动方向 【转】
- Windows Phone 开发之 设备方向
- 确定以后的方向
- 如何识别ios设备的方向
- iOS监听设备方向的方法
- ios开发之检测UIScrollView的滚动方向
- ios 设备方向判断
- 判断ios设备方向。
- IOS 判断设备方向
- android 没有出现menu 按键显示 解决
- 为什么程序员不擅长估算时间?
- 多小联合5-1011判断组合数的奇偶性
- ZRMM178 GR
- MFC如何避免闪烁
- ios开发之确定设备当前的方向
- javascript学习笔记—简单的动态选择收件人/联系人
- Objective C对象之间信息传递(一)
- 获得Android设备公网所在的ip
- 结构体打包#pragma
- 关于C++中的前置声明(1)
- Miss Nev:破解最后100米的配送难题
- <Codeforces Beta Round #38> D. Vasya the Architect
- 30天自制操作系统 导读