CAL001-CoreMotion实战
来源:互联网 发布:中金佳成 知乎 编辑:程序博客网 时间:2024/06/06 21:10
lihux原创程序git地址:https://github.com/lihux/lihuxCoreMotionTest
实战:
1. Xcode新建一个空工程:LihuxCoreMotionTest;
2.工程配置文件中添加CoreMotion.framework框架;
3.新建一个继承自UIViewController的VC:LHCoreMotionViewController(创建时勾选上附带xib文件)
5.LHCoreMotionViewController.m包含<CoreMotion/CoreMotion.h>头文件
6.xib中添加UI,同时连接到LHCoreMotionViewController.m:
@property (weak, nonatomic) IBOutlet UILabel *xLabel;
@property (weak, nonatomic) IBOutlet UILabel *yLabel;
@property (weak, nonatomic) IBOutlet UILabel *zLabel;
@property (weak, nonatomic) IBOutlet UIProgressView *xBar;
@property (weak, nonatomic) IBOutlet UIProgressView *yBar;
@property (weak, nonatomic) IBOutlet UIProgressView *zBar;
7.新增获取运动信息的成员变量:
@property (strong, nonatomic) CMMotionManager *motionManger;
@property (strong, nonatomic) NSOperationQueue *queue;
8.采用pull的方式每个0.1秒获取一次运动信息(加速度):放入viewdidload方法中调用即可:
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"CoreMotion框架测试20140109";
[self updateAccelerationInfomation];
}
- (void)updateAccelerationInfomation
{
self.motionManger = [[CMMotionManager alloc] init];
self.motionManger.accelerometerUpdateInterval = TENHZ;
if (self.motionManger.accelerometerAvailable) {
NSLog(@"Accelermeter availaber");
self.queue = [NSOperationQueue currentQueue];
[self.motionManger startAccelerometerUpdatesToQueue:self.queue withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
CMAcceleration acceleration = accelerometerData.acceleration;
self.xLabel.text = [NSString stringWithFormat:@"%.5f", acceleration.x];
self.xBar.progress = ABS(acceleration.x);
self.yLabel.text = [NSString stringWithFormat:@"%.5f", acceleration.y];
self.yBar.progress = ABS(acceleration.y);
self.zLabel.text = [NSString stringWithFormat:@"%.5f", acceleration.z];
self.zBar.progress = ABS(acceleration.z);
}];
}
}
10.大功告成运行截图(因为是要使用传感器,所以必须真机测试才行):真机为iphone4s+ios6
1.进入工程文件夹,创建git管理:
>>git init //初始化git
>>git add . //将当前工程所有文件添加到git暂存区中
>>git commit -m “开天辟地” //提交首个commit
2.将本地git管理的工程同步到GitHub账号中去:
>>登陆GitHub(如没有账号可先注册一个);
创建一个新的仓库(repository),按照提示提交文件即可:
git remote add origin git@github.com:linux/lihuxCoreMotionTest.git
git push -u origin master //master->origin,文件上传
git pull —rebase //origin->master, git下载,同时执行变基操作
要获取该源码,可在终端输入:
git clone git@github.com:lihux/lihuxCoreMotionTest.git
- CAL001-CoreMotion实战
- CoreMotion
- IOS CoreMotion
- CoreMotion(简介)
- CoreMotion框架
- ios coremotion 之CMStepCounter
- iOS使用CoreMotion
- iOS之 CoreMotion 框架
- 19.CoreMotion(陀螺仪)
- CoreMotion 使用心得
- CoreMotion iOS陀螺仪使用
- iOS 开发之传感器的使用—<CoreMotion/CoreMotion.h>
- CoreMotion初探及问题总结
- ios中陀螺仪CoreMotion的使用
- ios中陀螺仪CoreMotion的使用
- ios中陀螺仪CoreMotion的用法
- ios中陀螺仪CoreMotion的使用
- CoreMotion可以测到的各种值
- C陷阱与缺陷二.1
- 2014年电子科技市场衰退
- readelf 程序头节
- Linux 命令 alternatives和update-alternatives
- MySQL变量参数
- CAL001-CoreMotion实战
- U盘量产的注意事项
- linux删除文件中含有某字符的行
- HTML5画布WebGL,文件Three.js控制的锥
- 0xC0000005: 读取位置 0x00000000 时发生访问冲突
- git 某次提交补丁的生成与应用 (patch)
- java设计模式(5)---工厂方法模式
- 如何使用 Eclipse 插件和简洁的 Groovy 语言在 EC2 上快速地建立和运行简单的 Web 应用程序
- 第一章 什么是数组名?----一个让你吃惊的事实!