iOS/이슈
[iOS Issue] Shadow 관련 run time issue
Sky Titan
2023. 1. 7. 15:42
728x90
How to fix "Optimization Opportunities"
I'm using xcode 12. I wrote extension UI View as below: @IBInspectable public var shadowRadius: CGFloat { get { return layer.shadowRadius } set { layer.shadowRadius = ne...
stackoverflow.com

UIView에 shadow를 입히고 UITableView에서 scroll 가능한 상태로 두면, runtime issue로 다음과 같은 warning이 뜨게 된다.
UIView를 rendering할 때 shadow효과는 굉장히 expensive한 작업이고, scroll을 하게 되면 이동할 때마다 shadow를 rendering을 해줘야해서 app의 퍼포먼스에 악영향을 미친다는 내용이다.
Solution
- shadowPath를 명시적으로 지정해주어서 shadow를 rendering해야할 부분을 알려주는 것
- rasterize를 통하여 반복적인 shadow rendering을 방지
yourViewWithShadow.layer.shadowPath = UIBezierPath(rect: yourViewWithShadow.bounds).cgPath
yourViewWithShadow.layer.shouldRasterize = true
yourViewWithShadow.layer.rasterizationScale = UIScreen.main.scale
728x90