UICollectionViewcell 上添加animationImages 动画点击后失效问题

UIImageView动画在UICollectionViewcell点击后动画和图片消失的问题,是因为UICollectionViewcell的高亮是导致的bug。只需要

UIImageView*livingImageView = [[UIImageViewalloc]init];

      livingImageView.contentMode = UIViewContentModeScaleAspectFill;

      livingImageView.backgroundColor=YWhiteColor;

      [self.contentViewaddSubview:livingImageView];

      [livingImageViewmas_remakeConstraints:^(MASConstraintMaker*make) {

          make.top.mas_equalTo(5);

          make.right.mas_equalTo(-6);

          make.height.width.mas_equalTo(10);

      }];

      self.livingImageView= livingImageView;

   // 开始动画

    NSMutableArray *imageArr = [NSMutableArray array];

    for(inti =0;i<=9;i++){

        NSString*imageName = [NSStringstringWithFormat:@"playing0000%d",i];

        UIImage*image = [UIImageimageNamed:imageName];

        [imageArraddObject:image];

    }

    self.livingImageView.animationImages= imageArr;

    self.livingImageView.highlightedAnimationImages = imageArr;

    self.livingImageView.animationRepeatCount = 0;

    self.livingImageView.animationDuration = 0.5;

    self.livingImageView.layer.cornerRadius = 2;

    self.livingImageView.layer.masksToBounds = YES;

 [self.livingImageView startAnimating];

这样是有问题的,点击后会便失效。


只需要加上

self.livingImageView.highlighted = YES;

这行代码就可以解决。

你可能感兴趣的:(UICollectionViewcell 上添加animationImages 动画点击后失效问题)