zoukankan      html  css  js  c++  java
  • UIImageView有关的帧动画

    纯代码:设置imageView帧动画

    @interface ViewController ()

    {

        UIImageView *_imgView;

        NSMutableArray<UIImage *> *_imageArr;

    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 300, 300, 200)];

        _imgView.image = [UIImage imageNamed:@"1.jpg"];

        [self.view addSubview:_imgView];

        

        // 1.1 实例化可变数组用来 加载所有的图片

        _imageArr = [NSMutableArray array];

        for (int i = 0; i<20; i++) {

            // 获取图片的名称

            NSString *imageName = [NSString stringWithFormat:@"%d", i+1];

            // 创建UIImage对象

            UIImage *image = [UIImage imageNamed:imageName];

            // 加入数组

            [_imageArr addObject:image];

        }

        

        // 开始按钮

        UIButton *imgViewButtonStart = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        [imgViewButtonStart setFrame:CGRectMake(20, 200, 200, 50)];

        [imgViewButtonStart setTitle:@"开始动画" forState:UIControlStateNormal];

        [imgViewButtonStart setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

        [imgViewButtonStart addTarget:self action:@selector(stratAction) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:imgViewButtonStart];

        // 暂停按钮

        UIButton *imgViewButtonStop = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        [imgViewButtonStop setFrame:CGRectMake(200, 200, 200, 50)];

        [imgViewButtonStop setTitle:@"停止动画" forState:UIControlStateNormal];

        [imgViewButtonStop setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

        [imgViewButtonStop addTarget:self action:@selector(stopAction) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:imgViewButtonStop];

        

        

    }

    #pragma mark - 开始动画

    - (void)stratAction {

        // 设置动画图片

        _imgView.animationImages = _imageArr;

        // 设置动画的播放次数

        _imgView.animationRepeatCount = 0;

        // 设置播放时长

        // 1秒30帧, 一张图片的时间 = 1/30 = 0.03333 20 * 0.0333

        _imgView.animationDuration = 1.0;

        // 开始动画

        [_imgView startAnimating];

        

    }

    #pragma mark - 结束动画

    - (void)stopAction {

        [_imgView stopAnimating];

    }

    @end

  • 相关阅读:
    【NOI2005T1】瑰丽华尔兹-DP单调队列优化
    【POJ1113】Wall-Graham-Scan算法求凸包
    【POJ1113】Wall-Graham-Scan算法求凸包
    【POJ2774】Long Long Message-求最长公共子串(后缀数组求法)
    【POJ2774】Long Long Message-求最长公共子串(后缀数组求法)
    【POJ2195】Going Home-最小费用最大流模板题
    【POJ2195】Going Home-最小费用最大流模板题
    【POJ1273】Drainage Ditches-最大流问题
    【POJ1273】Drainage Ditches-最大流问题
    codevs 1155 金明的预算方案
  • 原文地址:https://www.cnblogs.com/ZGSmile/p/5845469.html
Copyright © 2011-2022 走看看