iphone - Animation's performance is very poor when view's shadow is on

前端 未结 2 1736
死守一世寂寞
死守一世寂寞 2021-02-05 12:43

I have a UILabel with CALayer shadow on.And I just move it around via UIView animation.

The performance is poor and I can see the

相关标签:
2条回答
  • 2021-02-05 13:04

    You can greatly improve the performance of a CALayer’s shadow by using its shadowPath property—this allows it to draw the shadow without having to recalculate the alpha mask of the layer. For a rectangular view, you’d use it like this:

    theView.layer.shadowPath = [UIBezierPath bezierPathWithRect:theView.bounds].CGPath;
    

    or, if its corners are rounded,

    theView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:theView.bounds cornerRadius:theView.layer.cornerRadius].CGPath;
    

    Note that this is a shadow around the view’s borders—if you want better performance on the shadow on the text itself, you either need to use the label’s text-shadow properties (which sacrifice the niceties of CALayer shadows, like blur, for better rendering speed) or—a much more complicated option—create a CGPathRef to use as the layer’s shadowPath from the text glyphs themselves.

    0 讨论(0)
  • 2021-02-05 13:19

    Not sure if this is the answer you're looking for but I found this: Drop Shadow on UITextField text

    It may be better performance, I haven't tried it but it seems it would be.

    0 讨论(0)
提交回复
热议问题