固定
删除了动画,这解决了问题。
EDIT 我已经在plist文件中添加了更多数据,iv注意到它只是在整个数据库中,而不只是显示一个问题。我该如何解决这个问题?
我有以下代码在摇晃结束时触发。然而,在模拟器上它的工作正常,但在设备本身它不。它基本上可以发出很多电话,我可以听到很多次声音。
有没有办法阻止这种情况,并确保它只能在摇动时发射?
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
// Do your thing after shaking device
if ([plistArray count] == 0) {
self.text.text = @"Please Upgrade for more";
[Animations fadeIn:self.text andAnimationDuration:1.0 andWait:YES];
}
else {
AVAudioPlayer *showsound;
NSString *audiopath = [[NSBundle mainBundle] pathForResource:@"mouse1" ofType:@"wav"];
NSURL *audiourl = [NSURL fileURLWithPath:audiopath];
showsound = [[AVAudioPlayer alloc]initWithContentsOfURL:audiourl error:Nil];
[showsound play];
////display random quote from array
int randV = arc4random() % self.plistArray.count;
self.text.text = self.plistArray[randV];
[self.plistArray removeObjectAtIndex:randV];
//fade text in
[Animations fadeIn:self.text andAnimationDuration:1.0 andWait:YES];
//play sound
}
}
答案 0 :(得分:1)
-motionEnded
被多次调用。如果您只想隔离摇动,请执行以下操作:
#pragma mark - UIResponder motion event methods
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if ( motion == UIEventSubtypeMotionShake ) {
// do something only for shakes
NSLog(@"shaken ... ");
}
}