• ios 距离传感器和摇一摇


    //距离传感器,以注册通知的形式来实现的

     

    #import "ViewController.h"

     

    @interface ViewController ()

     

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        //1.开启距离传感器

        [UIDevice currentDevice].proximityMonitoringEnabled=YES;

        //2 注册通知进行监听

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

    }

    -(void)proximityMonitoring

    {

        BOOL state=[UIDevice currentDevice].proximityState;

        if (state) {

            NSLog(@"");

        }

        else

        {

            NSLog(@"");

        }

    }

    -(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

    {

        NSLog(@"手机自带,摇动手机触发事件");

    }

     

    -(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event

    {

        NSLog(@"摇动结束");

    }

    -(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event

    {

        NSLog(@"摇动被终止触发事件(来电了)");

    }

     

     

    -(void)dealloc

    {

        [[NSNotificationCenter defaultCenter]removeObserver:self];

    }

     

    @end

  • 相关阅读:
    JavaScript 操作CSS
    源码搭建LAMP服务器
    Modified 2 color sort
    python的网络库
    找出有序整数数组中下标与值相同的所有元素
    sql 查看Oralce 数据库连接状态
    oracle 快闪 sql
    Sql server dblink
    昆山桶装水/免费送货上门/
    C# Tostring() 格式大全 [转]
  • 原文地址:https://www.cnblogs.com/tangranyang/p/4659525.html
Copyright © 2020-2023  润新知