传感器:
据说分为这么几种:
1、影像传感器,2、亮度传感器,3、磁阻传感器,4、近接传感器,5、声波传感器,6、加速度传感器,7、角加速度传感器。
下面的是4、近接传感器
- (void)makeProximityMonitoringEnabled{
//开启接近手机传感器变黑
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
//增加通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sensorStateChange:) name:@"UIDeviceProximityStateDidChangeNotification" object:nil];
}
-(void)sensorStateChange:(NSNotificationCenter *)notification;
{
if ([[UIDevice currentDevice] proximityState] == YES) {
NSLog(@"接近了。。。。");
//接近时的操作
}else{
NSLog(@"离开了");
//离开时的操作
}
}