判断是不是有物体靠近屏幕
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//1.开启传感器
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
//2.监听设备发出的通知()
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ProximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil];
}
//处理通知
-(void)ProximityStateDidChange:(NSNotification *)note
{
NSLog(@"%@",note);
if ([UIDevice currentDevice].proximityState) {
NSLog(@"1");
}else
{
NSLog(@"2");
}
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
本文标题:判断是不是有物体靠近屏幕
本文链接:https://www.haomeiwen.com/subject/qwcdqxtx.html
网友评论