zoukankan      html  css  js  c++  java
  • 距离传感器 和摇一摇功能

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

  • 相关阅读:
    js上拉加载下拉刷新
    CSRF
    Linux 常用命令
    汇编语言:了解寄存器与内存模型
    Node 的fs模块
    pdf转为html查看pdf.js
    centOs升级
    H5新特性监听手机的返回键
    gsap
    使用 iframe + postMessage 实现跨域通信
  • 原文地址:https://www.cnblogs.com/yuwei0911/p/5430303.html
Copyright © 2011-2022 走看看