gpt4 book ai didi

objective-c - 如何防止自定义 UITableViewCells 在取消选择时闪烁白色?

转载 作者:技术小花猫 更新时间:2023-10-29 11:18:19 24 4
gpt4 key购买 nike

我有一个自定义的 UITableViewCell,它根据它所在的行改变颜色:

TableViewController.m

- (void)willDisplayCell:(GSRSongCell *)cell atIndexPath:(NSIndexPath *)indexPath;
{
if (indexPath.row % 2 == 0) {
[cell lighten];
} else {
[cell darken];
}
}

CustomTableViewCell.m

- (void)lighten
{
self.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
self.contentView.backgroundColor = [UIColor whiteColor];
self.primaryLabel.backgroundColor = [UIColor whiteColor];
self.secondaryLabel.backgroundColor = [UIColor whiteColor];
}
- (void)darken
{
UIColor *darkColor = [UIColor colorWithR:241 G:241 B:241 A:1];
self.selectedBackgroundView.backgroundColor = darkColor;
self.contentView.backgroundColor = darkColor;
self.primaryLabel.backgroundColor = darkColor;
self.secondaryLabel.backgroundColor = darkColor;
}

但是,当我调用 deselectRowAtIndexPath:animated:YES 时,动画在 selectedBackgroundColor 应该更暗的单元格中逐渐变为白色。

然后我意识到取消选择动画与selectedBackgroundColor无关;事实上,取消选择动画实际上是基于 tableView.backgroundColor 属性!

如何覆盖取消选择动画以淡化为单元格的背景色?

最佳答案

它实际上会动画回到单元格背景颜色,所以你也必须设置它

在lighten方法中加入这一行

self.backgroundColor = [UIColor whiteColor];

这是变暗的方法

self.backgroundColor = darkColor;

关于objective-c - 如何防止自定义 UITableViewCells 在取消选择时闪烁白色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10882400/

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