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

前端 未结 5 2058
再見小時候
再見小時候 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:36

    In your custom UICollectionViewCell subclass you could override the setSelected: as so:

    - (void)setSelected:(BOOL)selected {
        [super setSelected:selected];
    
        if (selected) {
            [self animateSelection];
        } else {
            [self animateDeselection];
        }
    }
    

    I have found that on repeated touches this method is called on a cell even if it's already selected so you may want to just check that you are really changing state before firing unwanted animations.

提交回复
热议问题