UIImageView帧动画

来源:互联网 发布:苹果mac快捷键删除 编辑:程序博客网 时间:2024/06/05 02:27

- (IBAction)onButtonClickHandler:(id)sender {

    

    UIImageView *heartImageView = [[UIImageViewalloc]initWithFrame:CGRectMake(100.0, 100.0, 50.0, 50.0)];

    [self.view addSubview:heartImageView];

    NSMutableArray *images = [[NSMutableArrayalloc]initWithCapacity:7];

    for (int i=1; i<=7; i++) {

        [images addObject:[UIImageimageNamed:[NSStringstringWithFormat:@"xxx%d.png",i]]];

    }

    

    heartImageView.animationImages = images;

    heartImageView.animationDuration = 0.4 ;

    heartImageView.animationRepeatCount = 1;

    [heartImageView startAnimating];

    [NSTimer scheduledTimerWithTimeInterval:heartImageView.animationDuration

                                     target:self

                                   selector:@selector(onFrameAnimationFinished:)

                                   userInfo:heartImageView

                                    repeats:NO];

}





- (void)onFrameAnimationFinished:(NSTimer *)timer{

    UIImageView * imageView = (UIImageView *)[timeruserInfo];

    [imageView removeFromSuperview];

}