美文网首页iOS开发之笔记摘录
日记篇之图片帧动画在滚动UICollectionView、点击C

日记篇之图片帧动画在滚动UICollectionView、点击C

作者: 平安喜乐698 | 来源:发表于2020-03-29 11:12 被阅读0次
目录

在UICollectionViewCell中调用了如下方法,正常显示动画。但滚动UICollectionView后动画却停止了。

-(void)fq_setupAni{
    //
    NSMutableArray *imgMuArr=[NSMutableArray arrayWithCapacity:8];
    for(int i=0;i<10;i++){
        NSString *imgName=[NSString stringWithFormat:@"voiceAnimateImg%02d",i+1];
        [imgMuArr addObject:[UIImage imageNamed:imgName]];
    }
    [self.typeImgV setAnimationImages:imgMuArr];
    [self.typeImgV setAnimationDuration:0.65];
    [self.typeImgV setAnimationRepeatCount:0];
    [self.typeImgV startAnimating];
}

解决办法,其实很简单。就是实现willDisplayCell、didSelectItemAtIndexPath代理方法,重新调用startAnimating就可以了

-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
    [(FQRoomCollectionViewCell *)cell fq_startAni];
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [(FQRoomCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath] fq_startAni];
}    
// FQRoomCollectionViewCell中实现以下方法
-(void)fq_startAni{
    [self.typeImgV startAnimating];
}

相关文章

网友评论

    本文标题:日记篇之图片帧动画在滚动UICollectionView、点击C

    本文链接:https://www.haomeiwen.com/subject/wkpyuhtx.html