Xcode 为什么我的翻转动画要翻转两次?

Xcode 为什么我的翻转动画要翻转两次?,xcode,uigesturerecognizer,flip,Xcode,Uigesturerecognizer,Flip,我有点小问题。我有一个UILabel,它有一个UILongPress手势识别器。当UILongPressGestureRecognitor被调用时,我的应用程序应该使用翻转动画切换到新视图 这是我用于手势识别器的代码: UILongPressGestureRecognizer *labelLongPressRecognizer; labelLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self

我有点小问题。我有一个UILabel,它有一个UILongPress手势识别器。当UILongPressGestureRecognitor被调用时,我的应用程序应该使用翻转动画切换到新视图

这是我用于手势识别器的代码:

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时,开关动画开始,但当我释放时,它会再次重复动画。所以基本上动画发生两次,我只希望它发生一次

有什么想法吗


提前感谢:)

您是否正在检查发件人状态,例如

- (void)LoadLabelSettings:(UILongPressGestureRecognizer *)sender 
{
    if (sender.state == UIGestureRecognizerStateEnded) // or whatever
        // then do the flipping stuff
}
查看“UILongPressGestureRecognitor类参考”的“概述”,其中谈到长按是连续的,我认为可能会触发许多事件: