iOS基础开发教程--加速器的使用1
加速器使用注意:
- 允许接近显示屏
- 发送通知
- (void)viewDidLoad{
[super viewDidLoad];
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil];
}
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];}- (void)proximityStateDidChange:(NSNotification *)noti{
if ([UIDevice currentDevice].proximityState) {
NSLog(@"有物体靠近当前设备");
} else {
NSLog(@"有物体离开当前设备");
}}
网友评论