美文网首页
传感器

传感器

作者: Hevin_Chen | 来源:发表于2016-09-21 12:25 被阅读5次

距离传感器的使用

//开启距离感应功能

[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(@"某个物体远离了设备屏幕");//屏幕会自动解锁

}

}

相关文章

网友评论

      本文标题:传感器

      本文链接:https://www.haomeiwen.com/subject/oilaettx.html