gpt4 book ai didi

iphone - 如何自定义 UICollectionViewCell 子类的选择状态?

转载 作者:IT王子 更新时间:2023-10-29 07:53:10 25 4
gpt4 key购买 nike

我有一个自定义的 UICollectionViewCell 子类,它覆盖 initWithFrame:layoutSubviews 来设置它的 View 。但是,我现在正在尝试做两件我遇到麻烦的事情。

1) 我试图在选择时自定义 UICollectionViewCell 的状态。例如,我想更改 UICollectionViewCell 中的 UIImageView 中的其中一张图像。

2) 我想为 UICollectionViewCell 中的 UIImage 制作动画(光反射)。

谁能指出我正确的方向?

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
MyCollectionViewCell *cell = (MyCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
[cell setSelected:YES];
}

最佳答案

在您的自定义 UICollectionViewCell 子类中,您可以在 isSelected 属性上实现 didSet

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
}
}
}

关于iphone - 如何自定义 UICollectionViewCell 子类的选择状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13657883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com