如何防止自定义UITableViewCells在取消选择时闪烁白色? [英] How do I prevent custom UITableViewCells from flashing white on deselecting?

查看:71
本文介绍了如何防止自定义UITableViewCells在取消选择时闪烁白色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a custom UITableViewCell which changes color based on which row it is in:

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 应该更暗的单元格中淡化为白色。

However, when I call deselectRowAtIndexPath:animated:YES, the animation fades to a white color in cells where the selectedBackgroundColor should be darker.

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

I then realised that the deselection animation has nothing to do with the selectedBackgroundColor; in fact, the deselection animation is actually based on the tableView.backgroundColor property!

如何覆盖取消选择动画淡出我单元格的背景颜色?

How can I override the deselection animation to fade to the background color of my cells?

推荐答案

它实际上会动画化回单元格背景颜色,因此您必须设置也是如此

It actually animates back to cell background color so you will have to set it too

以减亮方法添加此行

self.backgroundColor = [UIColor whiteColor];

,然后使用变暗方法

self.backgroundColor = darkColor;

这篇关于如何防止自定义UITableViewCells在取消选择时闪烁白色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆