读书笔记 --- 接近传感器
来源:互联网 发布:明礼仪知荣辱演讲稿 编辑:程序博客网 时间:2024/04/20 15:01
看到这章,突然觉得,这可能是可以做出很好玩应用的一个功能,下面是代码,很简单
<span style="font-size:18px;">@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; NSBundle *bundle = [NSBundle mainBundle]; self.imageTrashFull = [[UIImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Blend Trash Full" ofType:@"png"]]; self.imageTrashEmpty = [[UIImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Blend Trash Empty" ofType:@"png"]]; self.imageView.image = self.imageTrashFull;}-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:YES]; UIDevice *device =[UIDevice currentDevice]; //开启接近传感器 device.proximityMonitoringEnabled = YES; //设置通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityDidChange:) name:UIDeviceProximityStateDidChangeNotification object:device]; }-(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:YES]; UIDevice *device =[UIDevice currentDevice]; // 解除通知 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceProximityStateDidChangeNotification object:nil]; device.proximityMonitoringEnabled = NO;}- (void)proximityDidChange:(NSNotificationCenter *)notification{ if ([[UIDevice currentDevice] proximityState] == YES) { NSLog(@"用户接近"); self.imageView.image = self.imageTrashEmpty; } else { NSLog(@"用户离开"); self.imageView.image = self.imageTrashFull; }}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning];}@end</span>
更多干货,请支持原作:http://item.jd.com/11436547.html
0 0
- 读书笔记 --- 接近传感器
- 传感器--------接近传感器
- 环形接近传感器超高品质
- Android 接近传感器实现判断接听电话
- 工业级无线接近传感器发布
- 接近传感器(CM3652)在触摸屏手机中的应用
- Android 4.4中的距离/接近传感器 P-sensor(一)
- ltr_558als 光线传感器和接近传感器 probe 后默认开启导致的系统无法休眠
- 接近传感器 距离传感器 结构差异 硬件差异 导致 失效 ltr558 al3006
- 将接近传感器和环境光传感器封装在一起的优点
- 如何接近零Bug--《敏捷开发的艺术》读书笔记4
- 使用单一 I²C 总线组合多个接近传感器---凯利讯半导体
- Android传感器高级编程之读书笔记一
- 读书笔记—面向物联网的传感器网络综述
- 《第一行代码》读书笔记:第十二章/传感器的用法
- 读书笔记——Android特色开发,使用传感器
- 传感器
- 传感器
- twitter storm源码走读之8 -- TridentTopology创建过程详解 - 徽沪一郎
- Ubuntu 下的sqlmap,nmap,metasploit安装
- 判断system()执行shell脚本是否正常执行结束
- android 主题和样式-style和Theme的区别和使用
- VC++ ado连接数据库(可以在VC6.0使用,以access数据库为实例)(1)
- 读书笔记 --- 接近传感器
- Linux文件默认权限
- XMPP协议内容和格式
- 驾驭工作的两大“法宝”:时间管理和好心态
- 如果你不想在IT行业被替代,扮演好这7个角色之一
- 黑马程序员_循环控制与break continue总结
- LDO线性电压调节器
- MongoDB基本管理命令
- AES,MD5,BASE64,Paillier加密算法