传感器 - 距离传感器
2015-09-23 18:23
211 查看
// 距离传感器
// 温度传感器
// 磁力传感器
// 光传感器
// 湿度传感器
// 陀螺仪 -- 导航, 赛车游戏(角速度传感器)
// 运动传感器 - 加速度传感器 -- 摇一摇, 计步器
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 距离传感器 - 默认是关闭的
// 1. 开启距离传感器 - 开启之后就会实时监听
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
// 2. 当监听到有物体靠近设备时, 会调用通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ProximityStateDidChanged:) name:UIDeviceProximityStateDidChangeNotification object:nil];
}
- (void)ProximityStateDidChanged:(NSNotification *)noticefication
{
LogRed(@"%@",noticefication);
if ([UIDevice currentDevice].proximityState){
LogGreen(@"靠近-----靠近");
}else{
LogMagenta(@"离开 --- 离开");
}
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceProximityStateDidChangeNotification object:nil];
}
@end
// 温度传感器
// 磁力传感器
// 光传感器
// 湿度传感器
// 陀螺仪 -- 导航, 赛车游戏(角速度传感器)
// 运动传感器 - 加速度传感器 -- 摇一摇, 计步器
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 距离传感器 - 默认是关闭的
// 1. 开启距离传感器 - 开启之后就会实时监听
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
// 2. 当监听到有物体靠近设备时, 会调用通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ProximityStateDidChanged:) name:UIDeviceProximityStateDidChangeNotification object:nil];
}
- (void)ProximityStateDidChanged:(NSNotification *)noticefication
{
LogRed(@"%@",noticefication);
if ([UIDevice currentDevice].proximityState){
LogGreen(@"靠近-----靠近");
}else{
LogMagenta(@"离开 --- 离开");
}
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceProximityStateDidChangeNotification object:nil];
}
@end
相关文章推荐
- CSS----布局常见问题
- 2016年校招开始了,Are you ready ?
- hihocoder #1082 : 然而沼跃鱼早就看穿了一切
- KMP 算法
- UI 框架、ORM、权限系统
- 【linux学习笔记四】文件搜索命令
- C常用函数的实现
- Elasticsearch-PHP 配置
- 为a标签添加动态的请求参数
- Struts1和Struts2对照
- Storm具体的解释(二)、成为第一Storm申请书
- 手势识别功能(Gesture Recognizer)
- 10分钟掌握XML、JSON及其解析
- [网络流] HDOJ 5457 Hold Your Hand
- H5性能优化方案
- 图片自适应放大缩小
- jsp中显示list 以及 c:forEach标签的使用
- 分割字符串
- poj 1286 Necklace of Beads||poj 2409 Let it Bead Polya模板
- 用C开发一个简易的webserver