ios – 动画时透明的UITableViewCell闪烁背景

我有一个自定义背景颜色的UIViewController.在它的顶部有一个UITableView,UITableViewCells是半透明的(白色,不透明度为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];

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

- (void)tableView:(UITableView *)tableView willdisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
}

这是一个显示问题的gif:

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

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

解决方法

>创建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;
}

>删除MasterViewController.m中的willdisplayCell方法

- (void)tableView:(UITableView *)tableView willdisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
}

>更改MasterViewController.m中的cellForRowAtIndexPath方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    [self configureCell:cell atIndexPath:indexPath];
    return cell;
}

>在故事板中更改单元格的类类型

试一试:D

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...