Core Motion 加速器的使用步骤
来源:互联网 发布:洛奇英雄传n卡优化 编辑:程序博客网 时间:2024/04/30 16:50
两种使用方法
1. pull(用户主动获取,调用频率根据用户需求)
- (void)pull
{
// 1. 创建mgr
CMMotionManager *mgr = [[CMMotionManageralloc] init];
_mgr = mgr;
// 2. 判断加速器是否能够使用
if (mgr.isAccelerometerAvailable) {// 可以使用
// 3.开始获取
[mgr startAccelerometerUpdates];
// 此处已点击一次屏幕采集一次信息
}
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// 点击屏幕就获取采集信息
NSLog(@"x = %f y = %f z = %f ",_mgr.accelerometerData.acceleration.x ,_mgr.accelerometerData.acceleration.y,_mgr.accelerometerData.acceleration.z);
}
--------------------------- 华丽的分割线-----------------------
2. push (系统主动推送,调用频率高)
- (void)push
{
// 1.创建CoreMotion管理者
CMMotionManager *mgr = [[CMMotionManageralloc] init];
_mgr = mgr;
// 2.判断加速器是否能够使用(最好判断)
if(mgr.isAccelerometerAvailable){// 可以使用
// 3.设置获取时间间隙
mgr.accelerometerUpdateInterval = 1.0 / 30.0;// 1分钟30次
// 4.开始获取
[mgr startAccelerometerUpdatesToQueue:[NSOperationQueuemainQueue] withHandler:^(CMAccelerometerData *_Nullable accelerometerData, NSError * _Nullable error) {
if (!error) {// 采集成功
NSLog(@"x = %f y = %f z = %f ", accelerometerData.acceleration.x , accelerometerData.acceleration.y, accelerometerData.acceleration.z);
}
}];
}
}
@end
- Core Motion 加速器的使用步骤
- 21.0~21.5 加速器与陀螺仪 Core Motion
- iOS4 中 Core Motion 框架的介绍和使用
- iOS中Core Motion框架的介绍和使用
- iOS4中Core Motion框架的介绍和使用
- iOS4中Core Motion框架的介绍和使用
- iOS4中Core Motion框架的介绍和使用
- iOS4中Core Motion框架的介绍和使用
- iOS4中Core Motion框架的介绍和使用
- iOS4中Core Motion框架的介绍和使用
- iOS4中Core Motion框架的介绍和使用
- iOS4 中 Core Motion 框架的介绍和使用
- iOS中Core Motion框架的介绍和使用
- iOS4 中 Core Motion 框架的介绍和使用
- Core Motion
- Core Motion
- iOS高级进阶(1):iOS4 中 Core Motion 框架的介绍和使用
- X86模拟器加速器的使用
- android应用性能测试——cpu的占用率
- Android图片加载
- Source Insight:Symbol not found
- 使用.net 3.5的DataContractJsonSerializer进行JSON Serialization
- shell脚本
- Core Motion 加速器的使用步骤
- 可选类型(?)与强制解析运算符(!)
- Struts2拦截器
- JAVA中关于链表的操作和基本算法
- 杭电 Problem 3788 ZOJ问题
- 图像增强算法实现--图像边缘提取
- split分割字符串时的一些特殊分隔符
- uva10594 (无向图的最小费用流)
- 央视3.15吊打一大票互联网公司