您的位置:首页 > 其它

距离感应

2016-05-26 16:01 267 查看
距离感应器其实就那么几句话:

    [UIDevice currentDevice].proximityMonitoringEnabled = YES;

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(noticeReceive) name:UIDeviceProximityStateDidChangeNotification object:nil];

-(void)noticeReceive{

    

    

    if ([UIDevice currentDevice].proximityState) {

        NSLog(@"近距离,做你想做的");

      

    }else{

        NSLog(@"远距离");

    }

}

但要注意:感应器只有在竖屏的时候管用,当你的设备横屏时,抱歉,距离感应over..................千万注意
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: