CoreMotion
来源:互联网 发布:手机ping软件 编辑:程序博客网 时间:2024/06/12 07:32
#import "TRViewController.h"
#import <CoreMotion/CoreMotion.h>
#import <AVFoundation/AVFoundation.h>
@interface TRViewController ()<AVAudioPlayerDelegate>
@property (nonatomic,strong)AVAudioPlayer *player;
@property(nonatomic,strong)CMMotionManager* manager;
@property (weak, nonatomic) IBOutletUIButton *myBall;
@property (nonatomic,assign)CGRect oldFrame;
@property (weak, nonatomic) IBOutletUILabel *tip;
@property (weak, nonatomic) IBOutletUILabel *label;
@property (nonatomic,assign)BOOL bRet;
@property (strong,nonatomic) IBOutletCollection(UIView)NSArray *iv;
@end
@implementation TRViewController
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.manager = [[CMMotionManageralloc]init];
[self.managersetAccelerometerUpdateInterval:1.0/30];
[self.managerstartAccelerometerUpdates];
self.oldFrame =self.myBall.frame;
self.bRet =YES;
[NSTimerscheduledTimerWithTimeInterval:1.0/30target:selfselector:@selector(getInfo)userInfo:nilrepeats:YES];
}
-(void)getInfo
{
CMAcceleration acc =self.manager.accelerometerData.acceleration;
//NSLog(@"x = %f y = %f z = %f", acc.x, acc.y, acc.z);
self.myBall.center =CGPointMake(self.myBall.center.x + acc.x,self.myBall.center.y-acc.y);
if (self.myBall.center.x <0 || self.myBall.center.x >320 || self.myBall.center.y <0)
{
[UIViewanimateWithDuration:2animations:^{
self.myBall.frame =self.oldFrame;
}];
}
if (CGRectIntersectsRect(self.label.frame,self.myBall.frame) &&self.bRet ==YES)
{
self.bRet =NO;
self.tip.text =@"请靠边行驶";
[UIViewanimateWithDuration:5animations:^{
self.tip.alpha =0;
}completion:^(BOOL finisd)
{
self.tip.text =@"";
self.tip.alpha =1;
}];
}
for (UIView* ivin self.iv)
{
if (CGRectIntersectsRect(self.myBall.frame, iv.frame))
{
if (2 ==iv.tag)
{
UIAlertView* alertView = [[UIAlertViewalloc]initWithTitle:@"恭喜"message:@"你赢了" delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil];
[alertViewshow];
}
else if (1 == iv.tag)
{
UIImage* image = [UIImageimageNamed:@"IMG_0993.JPG"];
UIImageView* imageView = [[UIImageViewalloc]initWithImage:image];
imageView.frame =self.view.frame;
[self.viewaddSubview:imageView];
NSString *path=[[NSBundlemainBundle] pathForResource:@"ghost"ofType:@"mp3"];
NSURL *url = [NSURLfileURLWithPath:path];
self.player = [[AVAudioPlayeralloc]initWithContentsOfURL:urlerror:nil];
self.player.delegate =self;
[self.playerplay];
[UIViewanimateWithDuration:5.0animations:^{
imageView.alpha =0;
}completion:^(BOOL finished){
[imageViewremoveFromSuperview];
}];
}
[UIViewanimateWithDuration:2animations:^{
self.myBall.frame =self.oldFrame;
}];
NSLog(@"xxxxxxxxxxxxxxxx");
}
}
}
- CoreMotion
- IOS CoreMotion
- CoreMotion(简介)
- CoreMotion框架
- CAL001-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可以测到的各种值
- RDLC 图形报表预览时 “本地报表处理期间错误”
- 主成分分析
- 豆瓣客户端的实现09 源码分析
- HDU 3415 Max Sum of Max-K-sub-sequence 单调队列题解
- 最小哈希
- CoreMotion
- 关于使用apktool可以反编译无法回编译的解决问题
- 第二天接触OC的“类”、“对象”、“方法”
- [iOS]XML两种解析方法
- [Android 4.4.2] Oppo Find7 轻装版 MIUI 4.7.4 by crazyi
- uva 375 Inscribed Circles and Isosceles Triangles(等腰三角形内接圆)
- android SD卡自动升级流程
- Linux初步学习二
- [DELPHI-码农]理解 Delphi 的类(十) - 深入方法[15] - 调用其他单元的函数