Objc_帧动画-UIImageView动画

汤姆猫帧动画详解

    //创建一个图片视图
    UIImageView  *tomCat = [[UIImageView alloc] init];
    tomCat.frame = [[UIScreen mainScreen] bounds];
    tomCat.image = [UIImage imageNamed:@"0.jpg"];
    [self.view addSubview:tomCat];
    
    //给小猫咪添加 帧动画效果
    tomCat.animationDuration = 1;//设置帧动画的时长
    tomCat.animationRepeatCount = 0;//设置帧动画的重复次数   帧动画一直重复 0  UIView动画反动画 long_max
    
    //创建一个数组 里面存放UIImage
    NSMutableArray  *arr = [[NSMutableArray alloc] init];
    for (int i=0; i<28; i++) {
        NSString  *name = [NSString stringWithFormat:@"%d.jpg",i];//根据i的值 通过字符串拼接 将图片的名字拼接出来
        UIImage  *image = [UIImage imageNamed:name];//根据图片的名字创建图片
        [arr addObject:image];//将图片添加到数组中
    }
    
    tomCat.animationImages = arr;
    //开始动画
    [tomCat  startAnimating];
    // 停止动画
    [tomCat stopAnimating];
    // 判断是否正在进行帧动画
    [tomCat isAnimating]; //该方法返回值为bool类型 yes 代表正在进行帧动画  no 没有进行帧动画

猜你喜欢

转载自www.cnblogs.com/StevenHuSir/p/Objc_FrameAnimation.html