iOS UICollectionView 包含gif动画UIImageView消失bug

UICollectionView中放置imageView各种操作并不会导致什么问题, 但是这个imageView如果是animation的效果, 那么就会诡异的消失, 不知道是否算bug, 这时候需要给imageView和collectionView分别配置


修复方式

imageView 配置
//在uiimageview的内部设置高亮动画内容, 可以设置为默认相同的images地址

[self setHighlightedAnimationImages:images];
collectionView 配置
//没错, 就是在选中, 取消选中, 高亮, 取消高亮下都让cell的动画再开始播放

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    CustomCell * cell = (CustomCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if(cell){
        [cell.imageView startAnimating];
    }
}

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    CustomCell * cell = (CustomCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if(cell){
        [cell.imageView startAnimating];
    }
}

-(void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    CustomCell * cell = (CustomCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if(cell){
        [cell.imageView startAnimating];
    }
}
-(void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    CustomCell * cell = (CustomCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if(cell){
        [cell.imageView startAnimating];
    }
}

屏蔽方式

可以将collectionView的cell交互禁掉

layerCollection.allowsSelection = false;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容