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

发布于 2024-12-05 13:31:50 字数 1280 浏览 0 评论 0 原文

我有一个小问题。我有一个 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 时,切换动画开始,但当我松开时,它会再次重复动画。所以基本上动画发生两次,我只想发生一次。

有什么想法吗?

提前致谢 :)

I'm having a little problem. I have an UILabel which have an UILongPressGestureRecognicer. When the UILongPressGestureRecognizer is called my app is supposed to switch to a new view using a flip animation.

This is the code I have used for the GestureRecognizer:

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

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

[NewLabel addGestureRecognizer:labelLongPressRecognizer];

and this is the code for the view switching animation:

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);

}

My problem is that when I hold down on my UILabel the switch animation begins, but when I release it repeats the animation again. So basically the animation occur twice and I only want it to take place once.

Any ideas?

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秉烛思 2024-12-12 13:31:50

您是否在检查发送者状态,例如,

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

查看“UILongPressGestureRecognizer Class Reference”的“概述”,其中谈到连续长按,我认为可能会触发许多事件:

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

Are you checking the sender state, e.g.,

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

Check out the "Overview" of the "UILongPressGestureRecognizer Class Reference", which talks about the long press being continuous and I presume numerous events could be triggered:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文