我有一个tableview,我自定义视图单元格,我想在它们上绘制阴影。我已经使用了视图的图层但是如果我通过这种方式绘制阴影,我的tableview非常慢。 这是代码:
UIView *foreground = [[UIView alloc] initWithFrame:CGRectMake(8., 8., 305, 290.)];
foreground.tag = kForegroundTag;
foreground.backgroundColor = [UIColor whiteColor];
/* Draw from here */
foreground.layer.shadowColor = [UIColor blackColor].CGColor;
foreground.layer.shadowOpacity = 0.7;
foreground.layer.shadowOffset = CGSizeMake(0., 1.);
foreground.layer.shadowRadius = 3.;
求你帮忙
答案 0 :(得分:0)
使用这些属性绘制阴影可能会导致性能下降。你有两个选择:
您可以在图层上设置shouldRasterize
以将其转换为将图层渲染为位图而不是重绘(请注意:这仅在您的视图不需要经常重绘时才有用,并且可能会结束如果在错误的场景中使用,则比现有的性能更差)
另一种选择是在图层上使用shadowPath
属性。根据{{1}}文档:
指定显式路径通常可以提高渲染性能
我肯定会使用CALayer
属性,并且根据视图的性质,可能还设置shadowPath
标志