重用 UITableViewCell 时光栅化的工作原理



如果我按如下方式设置光栅化:

- (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;
}

据我所知,系统应该为每个不同的单元格创建一个图像缓存。但是,如果每个单元格的标题都不同呢?系统如何确定哪个缓存图像可用于特定单元格?

在WWDC14上观看了会话419后,我发现有两个规则:

  • 光栅化的缓存大小限制为屏幕大小的 25.5 倍

  • 如果栅格化图像未使用超过 100 毫秒,则会从缓存中逐出这些图像

并在iPhone 6P上做配置文件显示只有当前屏幕会被缓存。

最新更新