使用cornerRadius进行Tableview滚动时缺乏性能,还有什么替代方法? [英] Tableview scrolling lack of performance using cornerRadius, whats alternatives?
问题描述
我找不到解决问题的方法,因此希望一些专家可以帮助我.
I can't find a solution for my issue, so I hope some experts could help me.
我的表格视图中有很多单元格.对于每个单元格,我都有一个带有圆角的图像视图:
I have tableview with lots of cells. For each cell I have an image view with rounded corners:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView *exampleView;
...
exampleView.layer.cornerRadius = 5.f;
exampleView.clipsToBounds = YES;
[cell.contentView addSubview:exampleView];
...
}
导致严重缺乏滚动性能问题-当使用cornerRadius和clipsToBounds = YES时,是否还有其他解决方案?(圆角图像视图包含图片,如果未设置角,则滚动很平滑.所以问题出在这里)
Resulting in a big lack of scrolling performance issue - when using cornerRadius and clipsToBounds = YES, any alternative solutions? (The rounded corner image view contains pictures, and if the corner isn't set. The scrolling is smooth. So the problem is here)
编辑#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 ];
编辑#2:就像myImage重叠在圆角视图上一样.如何使图像正确适合圆角视图?还是我想念什么?
EDIT #2: It's like myImage is lapping over the rounded corner view. How do I make the image fit the rounded corner view correct? or am I missing something?
推荐答案
只需更改以下行
exampleView.layer.masksToBounds = YES;
舍入imageView中的各个角.参见下面的图片.
To round out the corners in your imageView. See images below.
tableview滚动是视图合成的问题.除了上述建议之外,这肯定会有所帮助-设置UITableViewCell的contentView属性和backgroundView属性的opaque属性.前往:
The tableview scrolling is a issue with view compositing. In addition to suggestions above, this will certainly help - Set the opaque property of the UITableViewCell's contentView property, and backgroundView property. Go:
[cell.contentView setOpaque:YES];
[cell.backgroundView setOpaque:YES];
这将有助于尽早减少视图合成工作.
This will help reduce the view compositing effort at the earliest possible stage.
还有其他一些高级技术,这些技术要求您在滚动时使用异步处理来处理图像.如果上述技术有效,它们可能会杀伤力大.
There are additional, advanced, techniques which would require you to use asynchronous processing to process your images as you scroll. They may be overkill if the above techniques work.
这篇关于使用cornerRadius进行Tableview滚动时缺乏性能,还有什么替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!