传感器--------屏幕方向检测
2016-04-06 12:20
211 查看
首先添加通知, 记得在控制器销毁时移除通知就可以了, 不同方向需要实现的代码直接下载switch case 语句中就可以了
// // ViewController.m // 屏幕方向检测 // // Created by Wangjunling on 16/4/6. // Copyright © 2016年 Wangjunling. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //添加屏幕方向改变的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)orientationDidChange { switch ([UIDevice currentDevice].orientation) { case 0: NSLog(@"UIDeviceOrientationUnknown");//默认 break; case 1: NSLog(@"UIDeviceOrientationPortrait");//垂直向上 break; case 2: NSLog(@"UIDeviceOrientationPortraitUpsideDown");//垂直向下 break; case 3: NSLog(@"UIDeviceOrientationLandscapeLeft");//垂直向左 break; case 4: NSLog(@"UIDeviceOrientationLandscapeRight");//垂直向右 break; case 5: NSLog(@"UIDeviceOrientationFaceUp");//平放屏幕向上 break; case 6: NSLog(@"UIDeviceOrientationFaceDown");//平放屏幕朝下 break; default: break; } } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- android 传感器(OnSensorChanged)使用介绍
- Android重力传感器实现滚动的弹球
- 为什么三星手机一直坚持使用塑料外壳?
- iOS中传感器的基本使用
- 微软研究院为智能手机研发独特触控技术
- Android的常用传感器开发教程案例
- 利用传感器实现微信的摇一摇功能
- 高压电磁流量计的详细介绍及特点
- 如何才能提高便携式超声波流量计的精度
- VC下读取加速度计
- PSIM可视化智能安防
- PSIM智能可视化指挥管理系统
- JA检索-国际期刊S&T (Sensors and Transducers journal)
- 利用智能手机(Android)追踪一块磁铁(一)
- 利用智能手机(Android)追踪一块磁铁(二)
- andorid系统使用硬件资源_传感器1
- “面子”or“体验” 智能家居如何做设计?
- 什么才是真智能家居?
- 混战!智能家居炙手可热 市场规范有待提升