How can I customize the selection state of my UICollectionViewCell subclass?

前端 未结 5 2064
再見小時候
再見小時候 2021-02-01 04:02

I have a custom UICollectionViewCell subclass that overwrites initWithFrame: and layoutSubviews to setup its views. However, I\'m now trying to do two

5条回答
  •  情书的邮戳
    2021-02-01 04:34

    If you want to show animation on selection then following method might helpful to you :

     - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
         NSLog(@"cell #%d was selected", indexPath.row);
    
    
         // animate the cell user tapped on
         UICollectionViewCell  *cell = [collectionView cellForItemAtIndexPath:indexPath];
    
         [UIView animateWithDuration:0.8
                               delay:0
                             options:(UIViewAnimationOptionAllowUserInteraction)
                          animations:^{
                              [cell setBackgroundColor:UIColorFromRGB(0x05668d)];
                          }
                          completion:^(BOOL finished){
                              [cell setBackgroundColor:[UIColor clearColor]];
                          }
          ];
    
    
     }
    

提交回复
热议问题