帧动画

// 1.加载图片
    NSMutableArray *images = [NSMutableArray array];
    for (int i = 0; i < 10; i++) {
        NSString *imageName = [NSString stringWithFormat:@"qd_%d", i + 1];
        UIImage *image = [UIImage imageNamed:imageName];//imageName文件名  imageNamed:The image object for the specified file
        [images addObject:image];
    }
    _imageView = [UIImageView new];
    _imageView.frame = CGRectMake(100, 100, 320*ScreenWidths/750, 320*ScreenWidths/750);
    [self.view addSubview:_imageView];
    // 2. 把图片数组赋值给imageview的animationImages属性
    _imageView.animationImages = images;
    // 3.设置播放次数
    _imageView.animationRepeatCount = 0;
    // 4.设置执行时间
    // 默认:一秒30帧.
    // 当设置成1.0
    _imageView.animationDuration = 1.5;
    [_imageView startAnimating];
// [self.imageView stopAnimating];

 

// 暂停动画

- (void)pauseAnimation
{
    // 取出当前的时间点,就是暂停的时间点
    CFTimeInterval pausetime = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil];
    
    // 设定时间偏移量,让动画定格在那个时间点
    [self.layer setTimeOffset:pausetime];
    
    // 将速度设为0
    [self.layer setSpeed:0.0f];
    
}

// 恢复动画

- (void)resumeAnimation
{
    // 获取暂停的时间
    CFTimeInterval pausetime = self.layer.timeOffset;
    
    // 计算出此次播放时间(从暂停到现在,相隔了多久时间)
    CFTimeInterval starttime = CACurrentMediaTime() - pausetime;
    
    // 将时间偏移量设为0(重新开始);
    self.layer.timeOffset = 0.0;
    
    // 设置开始时间(beginTime是相对于父级对象的开始时间,系统会根据时间间隔帮我们算出什么时候开始动画)
    self.layer.beginTime = starttime;
    
    // 将速度恢复,设为1
    self.layer.speed = 1.0;
    
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值