您的位置:首页 > 编程语言

【代码笔记】检测手机翻转

2016-04-01 09:07 246 查看
一,代码。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

//监听手机方向改变事件
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
#pragma -mark -functions
//处理函数
-(void) orientationChanged
{
switch ([[UIDevice currentDevice] orientation]) {
case UIDeviceOrientationPortrait:
NSLog(@"portrait");
break;
case UIDeviceOrientationPortraitUpsideDown:
NSLog(@"portraitUpSideDown");
break;
case UIDeviceOrientationLandscapeLeft:
NSLog(@"landscapeLeft");
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"landscapeRight");
break;
case UIDeviceOrientationFaceDown:
NSLog(@"facedown!!");
break;
case UIDeviceOrientationFaceUp:
NSLog(@"FaceUp");
break;
default:
break;
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: