2011-09-18 75 views
0

我有一個小問題。我有一個擁有UILongPressGestureRecognicer的UILabel。當調用UILongPressGestureRecognizer時,我的應用程序應該使用翻轉動畫切換到新視圖。Xcode:爲什麼我的翻轉動畫翻轉兩次?

這是我用過的GestureRecognizer代碼:

UILongPressGestureRecognizer *labelLongPressRecognizer; 
labelLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LoadLabelSettings:)]; 

labelLongPressRecognizer.numberOfTouchesRequired = 1; 
labelLongPressRecognizer.minimumPressDuration = 2.0; 

[NewLabel addGestureRecognizer:labelLongPressRecognizer]; 

,這是該視圖的代碼轉換動畫:

CGContextRef context = UIGraphicsGetCurrentContext(); 

[UIView beginAnimations:nil context:context]; 
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:1.0]; 

[self.view addSubview:LabelSettingsViewController.view]; 

[UIView commitAnimations]; 

if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight || self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { 

    LabelSettingsViewController.view.frame = CGRectMake(0, 0, 480, 300); 

} 

我的問題是,當我按住我的UILabel開關動畫開始,但是當我釋放時,它會再次重複動畫。所以基本上動畫發生兩次,我只希望它發生一次。

任何想法?

感謝提前:)

回答

1

您檢查發件人狀態,例如,

- (void)LoadLabelSettings:(UILongPressGestureRecognizer *)sender 
{ 
    if (sender.state == UIGestureRecognizerStateEnded) // or whatever 
     // then do the flipping stuff 
} 

檢查出的「UILongPressGestureRecognizer類參考」,其中談到了長按是的「概述」連續的,我推測可能觸發大量事件:

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UILongPressGestureRecognizer_Class/Reference/Reference.html