阻止动画延迟不起作用

时间:2011-11-10 01:35:24

标签: ios uiviewanimation

首次调用此方法时,效果很好。

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

除延迟外,其他代码效果很好。

如何解决这个问题?

-(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];
            }];
        }];
    }
}

0 个答案:

没有答案