如何让动画在允许下一次用户输入之前完成

发布于 2024-09-13 04:07:15 字数 3860 浏览 3 评论 0原文

我有一些 UIImageViews,当用户触摸时,会开始具有一定持续时间的动画。触发器计数 ++,并在下一次触摸时开始播放另一个动画。 但是,如果用户快速触摸或进行双击,则第一个动画直到最后一帧才会完成。 我尝试了“sleep()”命令,但它不起作用。

    #pragma mark HenneAnimation
    if([touch view] == ani_Henne){

        //trigger strats with zero
        switch (trigHenne) {
            case 0:
//firstanimation 1 sec
                ani_Henne.animationImages = [NSArray arrayWithObjects:
                                             [UIImage imageNamed:@"ani_Henne01.png"],
                                             [UIImage imageNamed:@"ani_Henne01.png"],
                                             [UIImage imageNamed:@"ani_Henne02.png"],
                                             [UIImage imageNamed:@"ani_Henne01.png"],
                                             [UIImage imageNamed:@"ani_Henne01.png"],nil];


                ani_Henne.animationDuration = 1;
                ani_Henne.animationRepeatCount = 1;
                [ani_Henne startAnimating];
                [self.view addSubview:ani_Henne];

                trigHenne++;
                break;

            case 1:
//second animation 1 sec                
                ani_Henne.animationImages = [NSArray arrayWithObjects:

                                             [UIImage imageNamed:@"ani_Henne03.png"],
                                             [UIImage imageNamed:@"ani_Henne05.png"],
                                             [UIImage imageNamed:@"ani_Henne03.png"],
                                             [UIImage imageNamed:@"ani_Henne03.png"],
                                             [UIImage imageNamed:@"ani_Henne04.png"],
                                             [UIImage imageNamed:@"ani_Henne05.png"],
                                             [UIImage imageNamed:@"ani_Henne03.png"],nil];              
                ani_Henne.animationDuration = 3;
                ani_Henne.animationRepeatCount = 1;
            [ani_Henne startAnimating];
                [self.view addSubview:ani_Henne];

                trigHenne++;

                break;

            case 2:
                [self.view bringSubviewToFront:ani_Henne];

                ani_Henne.animationImages = [NSArray arrayWithObjects:
                                             [UIImage imageNamed:@"ani_Henne06.png"],
                                             [UIImage imageNamed:@"ani_Henne07.png"],
                                             [UIImage imageNamed:@"ani_Henne06.png"],
                                             [UIImage imageNamed:@"ani_Henne06.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne09.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne09.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne07.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne09.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],nil];

                ani_Henne.animationDuration = 2.75;
            ani_Henne.animationRepeatCount = 1;
                [ani_Henne startAnimating];
                [self.view addSubview:ani_Henne];

                trigHenne++;
                break;
            case 3:
                trigHenne=0;
// etc. animations
                break;
            default:
                break;  
        }       
    }

I have some UIImageViews and when the user is touching, an animation with a certain duration starts. A trigger counts ++ and with the next touch another animation starts to play.
But if the user touches to fast or make a doubletouch the first animation does not finish until the last frame.
I tried the "sleep()" command, but it does not work.

    #pragma mark HenneAnimation
    if([touch view] == ani_Henne){

        //trigger strats with zero
        switch (trigHenne) {
            case 0:
//firstanimation 1 sec
                ani_Henne.animationImages = [NSArray arrayWithObjects:
                                             [UIImage imageNamed:@"ani_Henne01.png"],
                                             [UIImage imageNamed:@"ani_Henne01.png"],
                                             [UIImage imageNamed:@"ani_Henne02.png"],
                                             [UIImage imageNamed:@"ani_Henne01.png"],
                                             [UIImage imageNamed:@"ani_Henne01.png"],nil];


                ani_Henne.animationDuration = 1;
                ani_Henne.animationRepeatCount = 1;
                [ani_Henne startAnimating];
                [self.view addSubview:ani_Henne];

                trigHenne++;
                break;

            case 1:
//second animation 1 sec                
                ani_Henne.animationImages = [NSArray arrayWithObjects:

                                             [UIImage imageNamed:@"ani_Henne03.png"],
                                             [UIImage imageNamed:@"ani_Henne05.png"],
                                             [UIImage imageNamed:@"ani_Henne03.png"],
                                             [UIImage imageNamed:@"ani_Henne03.png"],
                                             [UIImage imageNamed:@"ani_Henne04.png"],
                                             [UIImage imageNamed:@"ani_Henne05.png"],
                                             [UIImage imageNamed:@"ani_Henne03.png"],nil];              
                ani_Henne.animationDuration = 3;
                ani_Henne.animationRepeatCount = 1;
            [ani_Henne startAnimating];
                [self.view addSubview:ani_Henne];

                trigHenne++;

                break;

            case 2:
                [self.view bringSubviewToFront:ani_Henne];

                ani_Henne.animationImages = [NSArray arrayWithObjects:
                                             [UIImage imageNamed:@"ani_Henne06.png"],
                                             [UIImage imageNamed:@"ani_Henne07.png"],
                                             [UIImage imageNamed:@"ani_Henne06.png"],
                                             [UIImage imageNamed:@"ani_Henne06.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne09.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne09.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne07.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne09.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],nil];

                ani_Henne.animationDuration = 2.75;
            ani_Henne.animationRepeatCount = 1;
                [ani_Henne startAnimating];
                [self.view addSubview:ani_Henne];

                trigHenne++;
                break;
            case 3:
                trigHenne=0;
// etc. animations
                break;
            default:
                break;  
        }       
    }

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

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

发布评论

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

评论(2

深海夜未眠 2024-09-20 04:07:15

当您开始设置动画时,请禁用用户交互,完成后,重新启用它,如下所示:

yourImageView.userInteractionEnabled = NO;

yourImageView.userInteractionEnabled = YES;

您还可以延迟启用

...
[self performSelector:@selector(enable) withObject:yourImageView afterDelay:1.0];
...


-(void)enable
{
yourImageView.userInteractionEnabled = YES
}

When you begin to animate set the userinteraction disabled, and when you are done, reenable it like:

yourImageView.userInteractionEnabled = NO;

yourImageView.userInteractionEnabled = YES;

you could also delay the enabling with

...
[self performSelector:@selector(enable) withObject:yourImageView afterDelay:1.0];
...


-(void)enable
{
yourImageView.userInteractionEnabled = YES
}
乱世争霸 2024-09-20 04:07:15

使用 UIApplications beginIgnoringInteractionEvents 和 endIgnoringInteractionEvents 可能会对您有所帮助,当调用 begin 时,用户的 UI 交互事件将被忽略,这里有一个参考 UIApplication 参考

Using UIApplications beginIgnoringInteractionEvents and endIgnoringInteractionEvents might help you, when begin is called UI interaction events from user are ignored, here is a reference UIApplication ref

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