应用程序切换时UITableView分隔符闪烁

7

PS:我可以发布一个小视频,但这似乎是不必要的。

使用 Xcode 6.4(当前使用的版本为 6E35b)创建一个样例项目。创建一个简单的 UITableViewController 子类并使用故事板或编程方式进行渲染。

尝试应用程序切换。当应用程序进入后台或前台时,表视图分隔符似乎会闪烁。在滚动等情况下不会闪烁。

为了更好地查看它,请使用:

self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.rowHeight = 75.0f
self.tableView.separatorColor = self.view.tintColor;

我不确定为什么会出现这种情况。我参考了iPhone 6/6 Plus: UITableView separator flickering and different thickness,但是默认项目总是有一个启动屏幕 IB 文件。
您可以在 iOS 的默认设置应用程序中看到此问题。在大多数情况下,除非您渲染图像并突然出现白色分隔线闪烁,否则这不会成为问题。 编辑 1: 对我来说最大的问题是即使我使用:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

分隔符会短暂出现并消失,与其他情况完全相同。查看编辑2以了解更多详细信息。

编辑2(07/04/15, 8.46PM): 我希望在这里提供更多例子。我观察到的闪烁行为在自定义表格视图单元格中更为显著(即您可以自由渲染具有自定义属性设置等的自己的图像视图的情况)。

另一个观察是,在仅包含文本的单元格中,特定的闪烁行为(即在separatorStyle == UITableViewCellSeparatorStyleNone的情况下)不会引起注意。它主要在渲染图像的表视图单元格中引人注目。

  1. Here is an example of a table view cell:

    @interface BTableViewCell ()
    
    @property (nonatomic, strong, readwrite) UIImageView *mainImageView;
    
    @end
    
    @implementation BTableViewCell
    
    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self)
        {
            [self commonInit];
        }
        return self;
    }
    
    - (id)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
        if (self)
        {
            [self commonInit];
        }
        return self;
    }
    
    - (void)commonInit
    {
        // Initialize Avatar Image
        self.mainImageView = [[UIImageView alloc] init];
        _mainImageView.translatesAutoresizingMaskIntoConstraints = NO;
        _mainImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:_mainImageView];
    
        [self configureConstraintsForImageView];
    }
    
    - (void)configureConstraintsForImageView
    {
        [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_mainImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeHeight multiplier:1 constant:0]];
        [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_mainImageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeWidth multiplier:1 constant:0]];
    }
    
    @end
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        BTableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
    
        NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpeg"];
        UIImage* image = [UIImage imageWithContentsOfFile:imagePath];
        cell.mainImageView.image = image; //ignore unoptimized load
        return cell;
    }
    
  2. The flickering almost goes away if masksToBounds property is false. I am not sure why this would be the case or if this is the intended way.

  3. Instead of using a custom table view cell, use the default UITableViewCell class.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
    
        NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpeg"];
        UIImage* image = [UIImage imageWithContentsOfFile:imagePath];
        cell.backgroundView = [[UIImageView alloc] initWithImage:image];
        return cell;
    }
    
值得注意的是,#2#3的闪烁行为基本相同。与#1相比,它要微妙得多,但仍然很明显。

我还没有彻底调查这个问题,但分隔符中的闪烁效果让我想起了我在 UISegmentedControl 中遇到的问题。也许这个 Stack Overflow 的对话可以帮到你:https://dev59.com/7mMk5IYBdhLWcg3w3xnq#20654744 - Lobsterman
2个回答

1
添加。
Renders with edge antialiasing: YES

在您的应用程序属性列表中。

0

我曾经也遇到过同样的问题。我进行了长时间的研究,试图找到解决这个问题的方法,但是一直没有找到有用的东西。我得出结论,没有人注意到,而那些注意到的人并不在意appswitch表视图的0.6f线。但是我找到了一个小技巧,如果你仍然需要它的话。除了使用UITableViewCellSeparatorStyleNone之外,还要使用[self.tableView setSeparatorColor:[UIColor myColor]],最后一件事情是,如果你可以在单元格之间留有间隙,就像Facebook iOS应用程序一样,那么将背景颜色设置为一些灰色。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接