块动画延迟不起作用

发布于 2024-12-14 22:18:18 字数 1383 浏览 2 评论 0原文

当第一次调用这个方法时,效果很好。

第二次调用时,延迟不起作用。

除了延迟之外,其他代码运行良好。

我该如何解决这个问题?

-(void)makeParticle:(id)sender{

    Bubble *bubble=(Bubble*)sender;
    CGPoint center=bubble.center;

    NSInteger radian=arc4random()%360;
    for (int i=1; i<=13; i++) {
        NSInteger distance=20+arc4random()%80;
        radian+=10+arc4random()%40;
        UIImageView *iv=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"star%i.png",i]]]autorelease];
        NSInteger size=20+arc4random()%20;
        iv.frame=CGRectMake(0, 0, size, size);
        iv.center=center;
        iv.alpha=0;
        [self addSubview:iv];
        [iv release];

        [UIView animateWithDuration:0.4 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
            iv.alpha=0.5;
            iv.center=CGPointMake(center.x+distance*cos(radian), center.y+distance*sin(radian));
        } completion:^(BOOL finished) {

            [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
                iv.center=CGPointMake(600, 100);
                iv.alpha=0;
            } completion:^(BOOL finished) {
                [iv removeFromSuperview];
            }];
        }];
    }
}

When this method is first called, it works good.

On second call, the delay does not work.

The other code works good except for the delay.

How do I solve this problem?

-(void)makeParticle:(id)sender{

    Bubble *bubble=(Bubble*)sender;
    CGPoint center=bubble.center;

    NSInteger radian=arc4random()%360;
    for (int i=1; i<=13; i++) {
        NSInteger distance=20+arc4random()%80;
        radian+=10+arc4random()%40;
        UIImageView *iv=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"star%i.png",i]]]autorelease];
        NSInteger size=20+arc4random()%20;
        iv.frame=CGRectMake(0, 0, size, size);
        iv.center=center;
        iv.alpha=0;
        [self addSubview:iv];
        [iv release];

        [UIView animateWithDuration:0.4 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
            iv.alpha=0.5;
            iv.center=CGPointMake(center.x+distance*cos(radian), center.y+distance*sin(radian));
        } completion:^(BOOL finished) {

            [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
                iv.center=CGPointMake(600, 100);
                iv.alpha=0;
            } completion:^(BOOL finished) {
                [iv removeFromSuperview];
            }];
        }];
    }
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文