• 距离传感器 和摇一摇功能


    #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(@"停止摇一摇");
        
        
    }

  • 相关阅读:
    Daemon——守护进程
    RTMP
    CR LF CR/LF
    SO_REUSEADDR
    [aac @ ...] more samples than frame size (avcodec_encode_audio2)
    前端向后端传数据的方法
    控制层接受参数
    Swagger2
    net.sf.json------json解析
    springboot
  • 原文地址:https://www.cnblogs.com/yuwei0911/p/5430303.html
Copyright © 2020-2023  润新知