How can I customize the selection state of my UICollectionViewCell subclass?
In your custom UICollectionViewCell
subclass, you can implement didSet
on the isSelected
property.
Swift 3:
override var isSelected: Bool {
didSet {
if isSelected {
// animate selection
} else {
// animate deselection
}
}
}
Swift 2:
override var selected: Bool {
didSet {
if self.selected {
// animate selection
} else {
// animate deselection
}
}
}
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.