美文网首页
判断是不是有物体靠近屏幕

判断是不是有物体靠近屏幕

作者: 40dd4b561abe | 来源:发表于2017-06-13 10:26 被阅读2次
#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