首页 > 其他 > 详细

距离传感器 和摇一摇功能

时间:2016-04-25 13:12:35      阅读:137      评论:0      收藏:0      [点我收藏+]
#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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!