你好 我想灵敏度改变,当用户移动设备。目前它不是非常敏感,我相信它违约。我希望它更敏感,所以当用户摇动手机一点点时,声音就会播放。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];
}
}
哦,是不是有任何例子或任何东西? – LAA 2011-04-19 20:35:56