iPhone加速度计更改灵敏度-可可触控
||
你好
我希望在用户移动设备时改变灵敏度。目前它还不是很敏感,我相信它是默认的。我希望它更加灵敏,因此当用户稍微摇动手机时,声音就会播放。
这是代码
谢谢
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if(motion == UIEventSubtypeMotionShake)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@\"whip\" ofType:@\"wav\"];
if (theAudio) [theAudio release];
NSError *error = nil;
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error)
NSLog(@\"%@\",[error localizedDescription]);
theAudio.delegate = self;
[theAudio play];
}
}
没有找到相关结果
已邀请:
3 个回复
委婪绷冗诉
现在在您的实现中:
实现委托方法:
加速度计返回的x,y和z的值始终是-1.0到正1.0之间的浮点。您应该调用NSLog并将其x,y和z值输出到控制台,以便对它们的含义有所了解。然后,您可以开发一种简单的方法来检测运动。
久坡
镀建啼
然后在您的委托回调中: