标签:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//开启距离传感器监控开关
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
//监控proximityStateDidChange,
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(proximityStateDidChange) name:UIDeviceProximityStateDidChangeNotification object:nil];
}
//判断距离传感器的状态 , 判断接近还是远离
-(void)proximityStateDidChange {
if ([UIDevice currentDevice].proximityState) {
NSLog(@"接近");
}else{
NSLog(@"远离");
}
}
摇一摇功能:
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"开始摇一摇");
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"停止摇一摇");
}
标签:
原文地址:http://www.cnblogs.com/yuwei0911/p/5430303.html