2011-09-18 94 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