传感器
2016-09-21 本文已影响5人
Hevin_Chen
![](https://img.haomeiwen.com/i2185524/bbb0fd575d64fee3.png)
![](https://img.haomeiwen.com/i2185524/64ee0ac145858626.png)
![](https://img.haomeiwen.com/i2185524/d0d9d88722ea23fa.png)
![](https://img.haomeiwen.com/i2185524/fc38bf111ee95204.png)
![](https://img.haomeiwen.com/i2185524/6c10da7834d74f78.png)
![](https://img.haomeiwen.com/i2185524/342fc4cbe7b90007.png)
![](https://img.haomeiwen.com/i2185524/2b60b79d0465efb3.png)
![](https://img.haomeiwen.com/i2185524/f35bec5527544ae2.png)
![](https://img.haomeiwen.com/i2185524/7b08da4ca92d6519.png)
![](https://img.haomeiwen.com/i2185524/6316ba9bb0591867.png)
距离传感器的使用
//开启距离感应功能
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
//监听距离感应的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityChange:)
name:UIDeviceProximityStateDidChangeNotification object:nil];
- (void)proximityChange:(NSNotificationCenter *)notification {
if ([UIDevice currentDevice].proximityState==YES){
NSLog(@"某个物体靠近了设备屏幕");//屏幕会自动锁住
}else{
NSLog(@"某个物体远离了设备屏幕");//屏幕会自动解锁
}
}