
假设我在如下的 cell 复用代码中开启 rasterization,exampleTitles 的所有值都不相同
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *const cellIdentifier = @"UITableViewCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } cell.layer.shouldRasterize = YES; cell.layer.rasterizatiOnScale= [UIScreen mainScreen].scale; cell.textLabel.text = exampleTitles[indexPath.row]; return cell; } cell.layer.shouldRasterize = YES应该为 cell 生成了一个 bitmap 做缓存,但是在复用的情况下系统是怎么判定 bitmap 与 cell 的对应关系呢?缓存什么情况下会失效呢?
重看了WWDC14的session 419,以及离屏渲染优化详解:实例示范+性能测试这篇文章,再实际profile了一下,结论是:
两个原则: