PS:我可以发一个小视频,但好像没必要。
使用 Xcode 6.4(当前使用 6E35b
)创建示例项目。创建一个简单的 UITableViewController 子类并使用 Storyboard或以编程方式呈现它。
尝试应用切换。每当应用程序进入后台或前台时,表格 View 分隔符似乎都会闪烁。它不会在滚动时闪烁等。
为了更好地查看它,请使用:
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;
分隔符暂时呈现然后消失;与其他情况完全相同。有关详细信息,请参阅EDIT 2。
编辑 2(2015 年 7 月 4 日,晚上 8 点 46 分):我想在这里提供更多示例。我观察到的闪烁行为在自定义表格 View 单元格中更为突出(即您可以自由地使用自定义属性设置等呈现您自己的 ImageView )。
另一个观察结果是特定的闪烁行为(即在 separatorStyle == UITableViewCellSeparatorStyleNone
的情况下)对于纯文本单元格并不明显。在表格 View 单元格中呈现图像的情况下,它主要是引人注目的。
这是表格 View 单元格的示例:
@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; }
如果
masksToBounds
属性为false
,闪烁几乎消失。我不确定为什么会这样,或者这是否是预期的方式。不使用自定义表格 View 单元格,而是使用默认的
UITableViewCell
类。- (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 中的相比,它要微妙得多,但仍然很明显。
最佳答案
添加
Renders with edge antialiasing: YES
在你的应用列表中
关于ios - 应用程序切换期间 UITableView 分隔符闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31225138/