如何在动画图像完成后隐藏图像

时间:2014-07-25 18:35:22

标签: ios objective-c uiimageview

    Monster1Hit = YES;
    Monster1.animationImages = [NSArray arrayWithObjects:
                                [UIImage imageNamed:@"Explode1.png"],
                                [UIImage imageNamed:@"Explode2.png"],
                                [UIImage imageNamed:@"Explode3.png"],
                                [UIImage imageNamed:@"Explode4.png"],
                                [UIImage imageNamed:@"Explode5.png"],
                                [UIImage imageNamed:@"Explode7.png"],
                                [UIImage imageNamed:@"Explode8.png"],
                                [UIImage imageNamed:@"Explode9.png"],
                                [UIImage imageNamed:@"Explode10.png"],
                                [UIImage imageNamed:@"Explode11.png"],
                                [UIImage imageNamed:@"Explode12.png"],
                                [UIImage imageNamed:@"Explode13.png"], nil];
    [Monster1 setAnimationRepeatCount:1];
    Monster1.animationDuration = 1;
    [Monster1 startAnimating];

我希望在动画完成后隐藏图像,使其看起来像爆炸,图片消失。

3 个答案:

答案 0 :(得分:0)

在文档中,您可以看到我们有:

// for one cycle of images. default is number of images * 1/30th of a second (i.e. 30 fps)
@property(nonatomic) NSTimeInterval animationDuration;

这是图像视图类的属性。

因为您手动设置了此属性,所以您还可以创建一个计时器并在该持续时间之后触发它。

让它调用隐藏图像视图或其他任何需要的方法。

输入此代码:

[NSTimer scheduledTimerWithTimeInterval:1
                                     target:self
                                   selector:@selector(hideImageMethod) userInfo:nil
                                    repeats:NO];

[Monster1 startAnimating];

答案 1 :(得分:0)

创建一种方法,从视图层次结构中删除UIImageView

- (void)animationFinished:(NSObject *)notImportant {
    [Monster1 removeFromSuperview];
    // Or alternatively [Monster1 setHidden:YES];
}

并安排在动画完成时调用该方法。

// Put this right before [Monster1 startAnimating]
[self performSelector:@selector(animationFinished:) withObject:nil
    afterDelay:Monster1.animationDuration];

答案 2 :(得分:0)

如果你想做任何工作,你可以在动画持续时间之后调用函数,如下所示

[self performSelector:@selector(animationDidFinish:) withObject:nil
    afterDelay:Monster1.animationDuration]; //Do whataver you want to do in animationDidFinish: and start animation again if you want