动画时透明的UITableViewCell闪烁背景

Fre*_*ins 6 objective-c uitableview ios ios7

我有一个UIViewController自定义背景颜色.在它的上面有一个UITableViewUITableViewCells那些半透明(白色不透明度0.5).

我正在责备的问题和我撞到墙上的那个问题是在iOS 7中,当你有一个UITableViewCell半透明背景而你试图删除/插入/移动行时(依赖于动画效果) )整个UITableView细胞闪烁仅0.1秒,并将细胞背景设置为更透明的细胞.这非常烦人.

我唯一要做的就是设置背景颜色self.view:

self.view.backgroundColor = [UIColor colorWithRed:0.4 green:0.5 blue:0.7 alpha:1];
Run Code Online (Sandbox Code Playgroud)

并设置单元格的背景颜色:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
}
Run Code Online (Sandbox Code Playgroud)

这是一个显示问题的gif:

在此输入图像描述

这是超级简单的项目:https://github.com/socksz/TransparentCellFlashing

请帮我解决这个荒谬的问题!:P

Joi*_*gss 11

  1. 创建UITableViewCell的子类(如named:CustomCell),并覆盖CustomCell.m中的方法:

    - (id)initWithCoder:(NSCoder *)aDecoder{
        self = [super initWithCoder:aDecoder];
        if(self){
            // Initialization code
            [self setBackgroundColor:[UIColor clearColor]];
            UIView * bgView = [[UIView alloc] initWithFrame:self.frame];
            [bgView setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.5]];
            [self addSubview:bgView];
        }
        return self;
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 删除MasterViewController.m中的willDisplayCell方法

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. cellForRowAtIndexPath在MasterViewController.m中更改方法

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        [self configureCell:cell atIndexPath:indexPath];
        return cell;
    }
    
    Run Code Online (Sandbox Code Playgroud)
  4. 在故事板中更改单元格的类类型 在此输入图像描述

试一试:D

在此输入图像描述

  • 我爱你!它就像一个闪亮的魅力。为什么我们需要添加自定义视图作为背景视图?也许是因为“UITableViewCell”的“backgroundView”和“backgroundColor”属性以这种方式工作,而我们无法做任何事情来改变这种行为?谢啦!PS:GIF也+1 :-) (2认同)