你好 我想靈敏度改變,當用戶移動設備。目前它不是非常敏感,我相信它違約。我希望它更敏感,所以當用戶搖動手機一點點時,聲音就會播放。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