使用QuartzCore在UITmageView的UITmageView内圆角时的滚动体验很慢

fuz*_*uzz 5 iphone objective-c uitableview quartz-graphics

我用来QuartzCore在我UIImageView的细胞内添加圆角UITableView

这是我使用的代码:

fooImageView.layer.cornerRadius = 9.0;
fooImageView.layer.masksToBounds = YES;
fooImageView.layer.borderWidth = 1.0;
Run Code Online (Sandbox Code Playgroud)

问题是,当我添加此代码时.表格单元格的移动速度显着减慢.我只是想知道是否有其他替代方法可以使用这种技术滚动表格视图单元时更快地提高用户体验并提高性能?

我看到很多应用程序(大多数Twitter应用程序)在其单元格中应用圆角时没有性能下降.只是想知道他们如何克服"迟钝"?

谢谢你的帮助.

Stu*_*art 15

我要做的第一件事就是设置:

fooImageView.layer.shouldRasterize = YES;
Run Code Online (Sandbox Code Playgroud)

这会将圆角效果渲染为位图.我在前一段时间对视图使用CALayer效果时遇到了类似的问题UIScrollView,这种设置大大提高了性能.

别忘了设置

fooImageView.layer.rasterizationScale = [[UIScreen mainScreen] scale];
Run Code Online (Sandbox Code Playgroud)

防止像素化(设备错误分辨率的光栅化).


Mag*_*ave 5

我使用了3种提高UITableView性能的主要技术:

  1. 始终重复使用细胞,在创建新细胞时使用dequeuereusablecellwithidentifier.这可以防止操作系统在快速滚动时创建和销毁大量对象的开销.

  2. 折叠单元格的视图层次结构.创建自定义视图并在drawRect中完成所有单元格绘制,而不是拥有大量视图和子视图.像Twitter这样的应用程序使用这种方法进行超快速细胞绘制

  3. 确保您的图像不透明.您可以通过确保所有图像资源都没有烘焙到其中的Alpha通道并将图层的opaque属性设置为YES来执行此操作.

例子:

在cellForRowAtIndexPath中(表标识符字符串只是创建对相同类型的单元格的引用,可以是您喜欢的任何内容):

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
// Create a new cell if necessary
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SimpleTableIdentifier] autorelease];
}
Run Code Online (Sandbox Code Playgroud)

有关提高UITableViews性能的示例,请查看以下链接:http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007318-Intro -DontLinkElementID_2

希望这可以帮助,

戴夫