标签:
模拟器调节大小:打开模拟器,window->scale->选择大小
打开空白项目,打开ViewController.m文件,编写代码检测模拟器的方向:
- (void)viewDidLoad { [super viewDidLoad]; //检测模拟器方向的切换,NSNotificationCenter捕获消息通讯 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) //处理方向切换事件的方法 name:UIDeviceOrientationDidChangeNotification object:nil]; } //处理方向切换事件的方法 -(void) orientationChanged { switch ([[UIDevice currentDevice] orientation]) { case UIDeviceOrientationPortrait: //屏幕直立 NSLog(@">>>>>>>>>>>>>>>>>>>屏幕直立UIDeviceOrientationPortrait"); break; case UIDeviceOrientationPortraitUpsideDown: //屏幕直立,上下颠倒 NSLog(@">>>>>>>>>>>>>>>>>>>屏幕直立,上下颠倒UIDeviceOrientationPortraitUpsideDown"); break; case UIDeviceOrientationLandscapeLeft: //屏幕横向且屏幕向左 NSLog(@">>>>>>>>>>>>>>>>>>>屏幕横向且屏幕向左UIDeviceOrientationLandscapeLeft"); break; case UIDeviceOrientationLandscapeRight: //屏幕横向且屏幕向右 NSLog(@">>>>>>>>>>>>>>>>>>>屏幕横向且屏幕向右UIDeviceOrientationLandscapeRight"); break; case UIDeviceOrientationFaceDown: //屏幕面朝下 NSLog(@">>>>>>>>>>>>>>>>>>>屏幕面朝下UIDeviceOrientationFaceDown"); break; case UIDeviceOrientationFaceUp: //屏幕面朝上 NSLog(@">>>>>>>>>>>>>>>>>>>屏幕面朝上UIDeviceOrientationFaceUp"); break; default: break; } }
运行项目,打开模拟器,点击HardWare->Rotate Left 硬件->向左旋转屏幕,查看打印的日志:
2015-12-27 17:01:28.450 DemoApp[1387:35944] >>>>>>>>>>>>>>>>>>>屏幕横向且屏幕向右UIDeviceOrientationLandscapeRight 2015-12-27 17:01:58.030 DemoApp[1387:35944] >>>>>>>>>>>>>>>>>>>屏幕直立UIDeviceOrientationPortrait 2015-12-27 17:02:08.076 DemoApp[1387:35944] >>>>>>>>>>>>>>>>>>>屏幕横向且屏幕向左UIDeviceOrientationLandscapeLeft 2015-12-27 17:02:19.566 DemoApp[1387:35944] >>>>>>>>>>>>>>>>>>>屏幕直立,上下颠倒UIDeviceOrientationPortraitUpsideDown 2015-12-27 17:02:25.502 DemoApp[1387:35944] >>>>>>>>>>>>>>>>>>>屏幕横向且屏幕向右UIDeviceOrientationLandscapeRight 2015-12-27 17:02:32.699 DemoApp[1387:35944] >>>>>>>>>>>>>>>>>>>屏幕直立UIDeviceOrientationPortrait 2015-12-27 17:02:37.586 DemoApp[1387:35944] >>>>>>>>>>>>>>>>>>>屏幕横向且屏幕向左UIDeviceOrientationLandscapeLeft
标签:
原文地址:http://www.cnblogs.com/for-you/p/5080398.html