距离传感器的使用
- (void)ViewDidLoad {
// 打開距離傳感器,開啟距離檢測功能[UIDevice currentDevice].proximityMonitoringEnabled = YES;
// 監聽距離改變[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil]; }- (void)proximityStateDidChange:(NSNotification *)note {if ([UIDevice currentDevice].proximityState) {NSLog(@"有物體靠近設備屏幕");} else {NSLog(@"有物體遠離設備屏幕");} }
// 監聽距離改變[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil]; }- (void)proximityStateDidChange:(NSNotification *)note {if ([UIDevice currentDevice].proximityState) {NSLog(@"有物體靠近設備屏幕");} else {NSLog(@"有物體遠離設備屏幕");} }
?
轉載于:https://www.cnblogs.com/cdp-snail/p/4941975.html
總結
- 上一篇: mysql bison_使用flex和b
- 下一篇: 编译安装virtualbox 3.1.2