本文汇总了 Xcode 开发中遇到的一些常见问题及其解决方法,帮助开发者快速定位和修复问题。

Optimization Opportunities: The layer is using dynamic shadows which are expensive to render. If possible try setting shadowPath, or pre-rendering the shadow into an image and putting it under the layer.

这是因为没有设置shadowPath导致了离屏渲染
解决方法有两种:

  1. 通过明确地设置shadowPath来"引导"阴影渲染,例如
1
view.layer.shadowPath = UIBezierPath(rect: view.bounds).cgPath
  1. 缓存rasterization(珊格化)
1
2
view.layer.shouldRasterize = true
view.layer.rasterizationScale = UIScreen.main.scale