Drawing shadow with Quartz is slow on iPhone & iPad. Another way?

一曲冷凌霜 提交于 2019-11-29 21:03:46

You should set the shadowPath property. It is how CoreGraphics is able to optimize shadows.

For example, if your view is an opaque rectangle:

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

Thought I should make an answer because I didn't want this gem to get buried in the comments.

In addition to cobbal's answer above, which helped a lot, occulus also mentioned the following optimization for non-rectangular shadows, such as text shadows.

self.contentView.layer.shouldRasterize = YES;
// Fix visual degradation when rasterizing on high-density screens:
self.contentView.layer.rasterizationScale = [[UIScreen mainScreen] scale];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!