2014-04-04 61 views
-1

修復MotionEnded未在設備上工作

已刪除動畫並已解決該問題。

編輯 我已經將更多的數據添加到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

它看起來不像你過濾所有的動作類型,除了搖。 – Aaron

+0

我已經使用波紋管代碼if(motion == UIEventSubtypeMotionShake) { //您的代碼 } – user3246508

+0

但是,這dosent只顯示一個結果顯示所有 – user3246508

回答

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 ... "); 
    } 
} 
+0

我試過這個,仍然經歷plist文件中的所有數據? – user3246508

相關問題