实用知识:iOS5.0前加速计的方法使用(了解)
来源:互联网 发布:网络平台代理 编辑:程序博客网 时间:2024/06/07 05:16
#import "ViewController.h"//一个自己写的快速获取 frame 各属性的分类#import "UIView+ZUtility.h"@interface ViewController () <UIAccelerometerDelegate>@property (weak, nonatomic) IBOutlet UIImageView *imageView;// 加速计@property (strong, nonatomic) UIAccelerometer *accelerometer;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.accelerometer = [UIAccelerometer sharedAccelerometer]; // 代理回调 self.accelerometer.delegate = self; // 获取硬件数据的更新时间 self.accelerometer.updateInterval = 0.5;}#pragma mark UIAccelerometerDelegate- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{ // UIAcceleration 表示加速计的数据 // 稳定状态时, 0 ~ 1.0 或者 -1 ~ 0 , 手机的持握状态 // 1.0 实际上受到重力的作用 // 某个方向有比较大的动作时, 比较大的变化, 判断手机加速度// NSLog(@"%f, %f, %f", acceleration.x, acceleration.y, acceleration.z); /*================= 让图片滚动一下 =================*/ CGFloat xJSD = acceleration.x * 30; // 加速度 CGFloat yJSD = -acceleration.y * 30; self.imageView.x += xJSD; self.imageView.y += yJSD; if (self.imageView.x <= 0) { self.imageView.x = 0; } if (self.imageView.x >= (self.view.width - self.imageView.width)) { self.imageView.x = (self.view.width - self.imageView.width); } if (self.imageView.y <= 0) { self.imageView.y = 0; } if (self.imageView.y >= (self.view.height - self.imageView.height)) { self.imageView.y = (self.view.height - self.imageView.height); }}@end
0 0
- 实用知识:iOS5.0前加速计的方法使用(了解)
- 实用知识:CoreMotion框架使用(加速计方法使用)
- UIAccelerometer 加速计(iOS5就已经过期)
- 使用ajax前必须了解的知识
- 加速计.陀螺仪的使用
- 加速计知识1
- (九十二)加速计的用法(过期方法+新方法)
- 加速计(重力感应功能)的使用
- iOS加速计(陀螺仪)的使用
- 使用加速计获取设备的方向
- iOS_陀螺仪、加速计的使用
- 实用知识:摇一摇功能的方法使用(真简单??)
- 实用知识:陀螺仪的方法使用
- 实用知识:计步器的方法使用
- 实用知识:正则表达式的方法使用
- 实用知识:本地推送的方法使用
- 实用知识:音效播放的方法使用
- 实用知识:音乐播放的方法使用
- 在Cocos2d-x上实现横竖屏切换
- vim快速入门
- ubuntu16.04 nodejs 安装 node指令无效
- ZooKeeper实战(四)-ZooKeeper API使用
- 一个中国工程师的写照.
- 实用知识:iOS5.0前加速计的方法使用(了解)
- Android 权限
- hadoop基于文件的数据结构
- MongoDB 性能优化:分析执行计划
- CSS的两个class选择器紧挨在一起
- 水波纹
- 事件绑定与事件委托
- 移动小球和彩色波纹
- 实现无锁的栈与队列(4)