/**

*  CoreMotion

*

*/

#import "ViewController.h"

#import <CoreMotion/CoreMotion.h> // 导入框架

@interface ViewController ()

@property (nonatomic, strong) CMMotionManager *mgr;// 必须搞成全局的

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

//    [self push];

[self pull];

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

CMAcceleration acceleration = self.mgr.accelerometerData.acceleration;

LogRed(@"%f --- %f  ---- %f",acceleration.x, acceleration.y, acceleration.z);

}

/**

*  pull  --- 需要的时候, 采集

*/

- (void)pull

{

// 1. 创建运动管理者对象

self.mgr = [[CMMotionManager alloc] init];

// 2. 判断加速计是否可用

if (self.mgr.isAccelerometerAvailable) {

// 4. 开始采样  ---  pull

[self.mgr startAccelerometerUpdates];

}else{

LogGreen(@"加速计不可用");

}

}

/**

*  push --- 根据设置的采集时间间隔, 实时采集

*/

- (void)push

{

// 1. 创建运动管理者对象

self.mgr = [[CMMotionManager alloc] init];

// 2. 判断加速计是否可用

if (self.mgr.isAccelerometerAvailable) {

/**

*  accelerometerUpdateInterval --- 采样时间

isAccelerometerActive       --- 是否正在采集

startAccelerometerUpdates   --- pull

startAccelerometerUpdatesToQueue  --- push

stopAccelerometerUpdates    --- 停止采样

accelerometerData           --- 采集到的数据

*/

// 3. 设置采样间隔

self.mgr.accelerometerUpdateInterval = 1.0 / 30.0;

// 4. 开始采样

[self.mgr startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {

// 采集到数据时, 就会调用

if(error) return;

CMAcceleration acceleration = accelerometerData.acceleration;

LogRed(@"%f --- %f  ---- %f",acceleration.x, acceleration.y, acceleration.z);

}];

}else{

LogGreen(@"加速计不可用");

}

}

传感器- 加速计 - CoreMotion的更多相关文章

  1. 加速计 & CoreMotion

    CHENYILONG Blog 加速计 & CoreMotion 加速计 & CoreMotion 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微 ...

  2. Swift - 加速传感器(CoreMotion)的用法,小球加速运动并反弹样例

    1,加速传感器可以监听到x,y,z三个方向的加速度,使用步骤如下: (1)实例化CMMotionManager类 (2)向CMMotionManager的accelerometerUpdateInte ...

  3. iOS开发 传感器(加速计、摇一摇、计步器)

    一.传感器 1.什么是传感器传感器是一种感应\检测周围环境的一种装置, 目前已经广泛应用于智能手机上 传感器的作用用于感应\检测设备周边的信息不同类型的传感器, 检测的信息也不一样 iPhone中的下 ...

  4. iOS开发——高级篇——传感器(加速计、摇一摇、计步器)

    一.传感器 1.什么是传感器传感器是一种感应\检测周围环境的一种装置, 目前已经广泛应用于智能手机上 传感器的作用用于感应\检测设备周边的信息不同类型的传感器, 检测的信息也不一样 iPhone中的下 ...

  5. 推送通知/传感器/UIDynamic仿真(推送通知已适配iOS10)

    推送通知/传感器/UIDynamic 一.推送通知 1.推送通知简介 什么是推送通知 此处的推送通知与NSNotification没有任何关系 可以理解为,向用户推送一条信息来通知用户某件事情 作用: ...

  6. iOS 传感器集锦

    https://www.jianshu.com/p/5fc26af852b6 传感器集锦:指纹识别.运动传感器.加速计.环境光感.距离传感器.磁力计.陀螺仪   效果预览.gif 一.指纹识别 应用: ...

  7. iOS---开发实用传感器

    传感器 1.什么是传感器 传感器是一种感应\检测装置, 目前已经广泛应用于智能手机上 2.传感器的作用 用于感应\检测设备周边的信息 不同类型的传感器, 检测的信息也不一样 iPhone中的下面现象都 ...

  8. iphone传感器

    传感器 什么是传感器 传感器是一种感应\检测装置, 目前已经广泛应用于智能手机上 传感器的作用 用于感应\检测设备周边的信息 不同类型的传感器, 检测的信息也不一样 iPhone中的下面现象都是由传感 ...

  9. IOS UIDevice距离传感器(打开 关闭)

    ●  什么是传感器 ●  传感器是一种感应\检测装置, 目前已经广泛应用于智能手机上 ●  iPhone5中内置的传感器有 ●  运动传感器\加速度传感器\加速计(Motion/Acceleromet ...

随机推荐

  1. TCP并发server,每个客户一个子进程

    今天笔者带来的是server型号第一,这是最经常使用的模型的最基本的一个–TCP并发server,每个客户一个子进程. 首先简单介绍:TCP并发server,每个客户一个子进程,并发server调用f ...

  2. android优化(json工具,message新建/传递,avtivity深入学习视频)

    1,在线json校验工具:www.bejson.com 2, 在handler中经常使用的 message的传递上,message.what使用静态量 . private static final i ...

  3. 一款很不错的FLASH时种插件

    直接贴一段代码上来,大家看看效果: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  4. oracle表锁住 解锁办法

    第一种方法: 用系统账户如sys      as  SYSDBA 登录进去 1.查看数据库锁,诊断锁的来源及类型:  select object_id,session_id,locked_mode f ...

  5. Android(java)学习笔记155:如何让你的GridView不再滚动

    GridView显示不完整的原因是因为,他的外层也套用了一个滑动的控件,这个解决办法是:重写GridView,是控制GridView不能滚动,就是写一个类继承GridView   代码如下: publ ...

  6. Java client 访问 memcached

    在测试项目中引入了memcached作为缓存层,以下是memcached的缓存配置和调用过程. linux下memcached安装过程 直接参考以前的博文linux下安装memcached过程  不再 ...

  7. 使用 Date 和 SimpleDateFormat 类表示时间

    在程序开发中,经常需要处理日期和时间的相关数据,此时我们可以使用 java.util 包中的Date类.这个类最主要的作用就是获取当前时间,我们来看下Date的类的使用: Date d=new Dat ...

  8. (转)OpenVPN下载、安装、配置及使用详解

    原文地址:http://www.365mini.com/page/14.htm OpenVPN简介 OpenVPN是一个用于创建虚拟专用网络(Virtual Private Network)加密通道的 ...

  9. Web开发必备资源汇总[转]

    导读:原文来自< Best “must know” open sources to build the new Web>,译文由酷壳网陈皓整理编译< 开源中最好的Web开发的资源 & ...

  10. java 知识 链接

    www.java2blog.com/2016/04/hashmap-in-java-with-examples.html HashMap全剖析 http://card.weibo.com/articl ...