Tableview滚动使用cornerRadius缺乏性能,什么是替代品?

Ner*_*u-J 11 rounded-corners uitableview ios

我无法找到解决问题的方法,所以我希望有些专家可以帮助我.

我有很多细胞的tableview.对于每个单元格,我有一个带圆角的图像视图:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView *exampleView;

...
exampleView.layer.cornerRadius =   5.f;
exampleView.clipsToBounds = YES;   
[cell.contentView addSubview:exampleView];
...

}
Run Code Online (Sandbox Code Playgroud)

导致滚动性能问题严重不足 - 当使用cornerRadius和clipsToBounds = YES时,任何替代解决方案? (圆角图像视图包含图片,如果没有设置角落.滚动是平滑的.所以问题出在这里)

编辑#1:澄清我已阅读其他帖子:

...
exampleView.frame = CGRectMake(5.0f,size.height-15.0f,30.0f,30.0f);
exampleView.layer.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5].CGColor;
exampleView.layer.cornerRadius = 5.0f;
exampleView.layer.borderWidth       =   0.3f;
exampleView.layer.borderColor       =   [UIColor blackColor].CGColor;
exampleView.layer.masksToBounds = NO;
exampleView.layer.shouldRasterize = YES;
//exampleView.clipsToBounds = NO;
[exampleView setImage: myImage ];
Run Code Online (Sandbox Code Playgroud)

编辑#2: 就像myImage正在研究圆角视图.如何使图像适合圆角视图?还是我错过了什么?

小智 10

只需更改以下行

  exampleView.layer.masksToBounds = YES;
Run Code Online (Sandbox Code Playgroud)

使图像视角变圆.见下图.

tableview滚动是视图合成的问题.除了上面的建议,这肯定会有所帮助 - 设置UITableViewCell的contentView属性和backgroundView属性的opaque属性.走:

  [cell.contentView setOpaque:YES];
  [cell.backgroundView setOpaque:YES];
Run Code Online (Sandbox Code Playgroud)

这将有助于在尽可能早的阶段减少视图合成工作量.

还有一些额外的高级技术需要您在滚动时使用异步处理来处理图像.如果上述技术有效,它们可能会过度杀伤.

将图层的maskToBounds设置为yes的UIImageView 将图层的maskToBounds设置为No的UIImageView