🚨문제상황
- 셀 내부이미지에 shadow를 적용했지만 최초 실행 시 보이지 않음
- 스크롤 후 다시 돌아오면 그림자가 정상적으로 보임
- 아래 사진 순서 대로 1,2번은 안보이고 스크롤 하면 3번부터 보임, 다시 돌아오면 2,1 순으로 그림자가 생김
🔎 문제 원인
- AutoLayout이 완전히 적용되기 전에 shadowPath 설정
- containerView.bounds가 아직 계산되지 않은 상태여서 (0,0,0,0)이 찍힘
override func layoutSubviews() {
super.layoutSubviews()
containerView.layer.shadowPath = UIBezierPath(
roundedRect: containerView.bounds, // ❌ 초기에 bounds가 (0,0,0,0)
cornerRadius: 16
).cgPath
}
🧚🏻 해결 방법
override func layoutSubviews() {
super.layoutSubviews()
// containerView.bounds 대신 Constraints와 같은 계산된 크기 직접 사용
containerView.layer.shadowPath = UIBezierPath(
roundedRect: CGRect(
x: 0, y: 0,
width: contentView.bounds.width,
height: contentView.bounds.width * 1.15
),
cornerRadius: 16
).cgPath
}
DispatchQueue를 사용하는 방법도 있지만 간단하게 해결하고 싶어서 택한 방법이다!
'iOS' 카테고리의 다른 글
[iOS] Factory Pattern (3) | 2025.07.24 |
---|---|
[iOS] Coordinator 패턴 적용기 (0) | 2025.07.22 |
[iOS] Coordinator 패턴으로 화면 전환 로직 분리하기 (0) | 2025.07.10 |
[iOS] 클로저에서 async/await로 리팩토링하기 (1) | 2025.07.08 |
[iOS] 성능 최적화: @inlinable과 lazy (1) | 2025.06.25 |