我有一点问题。我有一个UILabel,它有一个UILongPressGestureRecognicer。当调用UILongPressGestureRecognizer时,我的应用程序应该使用翻转动画切换到新视图。
这是我用于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时,切换动画开始,但是当我释放它时,它会再次重复动画。所以基本上动画会出现两次,我只希望它发生一次。
有什么想法吗?
提前致谢:)
答案 0 :(得分:1)
您是否正在检查发件人状态,例如,
- (void)LoadLabelSettings:(UILongPressGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded) // or whatever
// then do the flipping stuff
}
查看“UILongPressGestureRecognizer类参考”的“概述”,其中讨论了长按连续,我假设可以触发许多事件: