【问题标题】:How i can draw the shadow for my uiview我如何为我的 uiview 绘制阴影
【发布时间】:2012-08-29 22:04:00
【问题描述】:

我有一个表格视图,我在其中自定义了视图单元格,我想在它们上绘制阴影。我已经使用了视图的图层,但是如果我通过这种方式绘制阴影,我的 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.;

谢谢你的帮助

【问题讨论】:

    标签: ios uiview drawing shadow


    【解决方案1】:

    使用这些属性绘制阴影的性能会很差。不过,您有两种选择:

    您可以在图层上设置shouldRasterize 以将其转换为将图层渲染为位图而不是重绘(注意:这仅在您的视图不需要经常重绘时有用,并且最终可能会变得更糟如果在错误的场景中使用,则优于现有性能)

    另一个选项是在图层上也使用shadowPath 属性。根据CALayer 文档:

    指定显式路径通常会提高渲染性能

    我肯定会使用shadowPath 属性,并且根据视图的性质,可能还会设置shouldRasterize 标志

    【讨论】:

    • 最近在 Quora 上的回答也表明 shadowPath 属性是可行的方法并给出了一个示例用法:quora.com/iOS-Development/…
    • 谢谢你非常非常多:D 我现在有 60fps :) thx 链接
    猜你喜欢
    • 2010-10-22
    • 2016-11-14
    • 2011-02-25
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    相关资源
    最近更新 更多