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;
這行代碼就可以解決。