帧动画的应用------自己在用的时候写了 估计一些刚入门的可能还不会用,就写出来留给大家使用

#import "ViewController.h"

#define  ScreenWidth [[UIScreen mainScreen]bounds].size.width

#define  ScreenHeight [[UIScreen mainScreen]bounds].size.height

@interface ViewController ()

{

    UIImageView *_fireImage;

    UIButton *_pauseButton;

}


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    

    //  创建火焰背景

    _fireImage=[[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];

    _fireImage.image=[UIImage imageNamed:@"fire.png"];

    [self.view addSubview:_fireImage];

    

    

    //  创建火焰数组

    NSMutableArray *imageArray=[[NSMutableArray alloc] init];

    //for循环向数组中添加 UIImage类型的对象

    for(int i=0;i<2;i++)

    {

        //获得图片名称

        NSString *imageName=[NSString stringWithFormat:

                             @"loading%d.png",i];

        UIImage *imageFire=[UIImage imageNamed:imageName];

        [imageArray addObject:imageFire];

    }

    

    

    _fireImage.animationDuration=0.5;

    _fireImage.animationImages=imageArray;

    [_fireImage startAnimating];

    

    

    _pauseButton=[UIButton buttonWithType:UIButtonTypeSystem];

    _pauseButton.frame=CGRectMake(20,20,30,20);

    [_pauseButton setTitle:@"暂停" forState:UIControlStateNormal

     ];

    [_pauseButton addTarget:self action:@selector(pauseClick) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:_pauseButton];



}

- (void)pauseClick

{

    NSLog(@"调用了");

    //static bool isStop=NO;

    //isStop=!isStop;

    //  isAnimating判断当前是否正在动画 ;如果 是,停止动画;否则,开始动画

    bool result=[_fireImage isAnimating];

    if(result)

    {

        //停止动画  ;停止的时候,显示的图片是 _fireView最初赋值的图片

        //Timer区别在于,Timer停止时显示最后一张照片,而帧动画停止时显示最初赋值的照片

        [_fireImage stopAnimating];

        [_pauseButton setTitle:@"开始" forState:UIControlStateNormal];

    }

    else

    {

        [_fireImage startAnimating];

        [_pauseButton setTitle:@"暂停" forState:UIControlStateNormal];

    }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值