
scrollView에 collectionView를 넣었을때 왼쪽 사진과 같이 superView의 top부터 시작하여 navigationBar를 가린 상태로 나오도록 하고 싶었다.
여러가지 방법들을 찾아보던중 adjustedContentInset과 contentInsetAdjustmentBehavior로 간단하게 해결할 수 있었다.
adjustedContentInset
adjustedContentInset은 contentInset과 같은 UIEdgeInsets타입이지만
adjustedContentInset → get만 가능
contentInset → get, set 둘다 가능
contentInset은 개발자가 직접 inset을 넣어줄 수 있지만, adjustedContentInset은 Xcode에서 자동으로 넣어주기 때문에 수정할 수 없고 읽기만 가능하다.
adjustedContentInset은 contentInset과 system Inset을 더한 값이라고 하는데
여기서 system Inset은 contentInsetAdjustmentBehavior로 결정되는 값이라고 한다.
contentInsetAdjustmentBehavior
공식문서에서 contentInsetAdjustmentBehavior를 찾아보면 아래와 같이 4가지 옵션이 있는것을 볼 수 있다.

스토리보드에서의 scrollView의 contentInsetAdjustmentBehavior 기본값은 automatic으로 되어있는데
scrollview가 navigation Controller에서 사용되고 있기 때문에 자동으로 inset을 조정해 navigationBar를 가리지 않는 것이였다.

가리지 않는 것이였다. scrollView의 contentInsetAdjustmentBehavior 값을 never로 변경해주고 실행하면 아래 사진과 같이 superView의 top부터 시작하여 navigationBar를 가린 상태로 나오게 된다.

참고
https://zeddios.tistory.com/809
iOS ) adjustedContentInset / contentInsetAdjustmentBehavior
안녕하세요 :) Zedd입니다.애플 이벤트..요약을 봤는데 ㅎㅡㅁ......... ㅋㅋ와치가 젤 웃김와치에 나침반이 들어가게 됩니다 (두둥) 외국은 나침반이 좀 특별한가..?한국은 진짜 어쩌라고자나요 됐
zeddios.tistory.com
'iOS' 카테고리의 다른 글
| iOS - 커스텀뷰를 테이블뷰와 비슷하게 사용하기 (0) | 2023.07.11 |
|---|---|
| iOS - 텍스트의 특정 부분만 Bold 처리하기 (0) | 2023.06.11 |
| NavigationController 사용시 status Bar Style 바꾸기 (0) | 2022.12.15 |
| UICollectionViewCompositionalLayout에서 Cell 동적 높이 적용하기 (0) | 2022.11.01 |
| UINavigationBar TitleView Swipe-Back 했을때 Width 커지는 현상 (0) | 2022.10.24 |