UIScrollView์˜ ContentInset, ContentOffset, ContentSize์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณธ๋‹ค.

ํ•ต์‹ฌ ์š”์•ฝ

ContentOffset, ContentInset, and ContentSize of a UI ScrollView์— ์ข‹์€ ์‚ฌ์ง„์ด ์žˆ์–ด ๊ณต์œ ํ•œ๋‹ค.

ContentInset

  • safe area ํ˜น์€ scrollView์˜ ๊ฐ€์žฅ ์ž๋ฆฌ๋กœ๋ถ€ํ„ฐ ์–ด๋Š์ •๋„ ๋–จ์–ด์ ธ์žˆ๋Š”์ง€๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’
  • ์ฆ‰, ์—ฌ๋ฐฑ

ContentOffset

  • ์Šคํฌ๋กค ๋ทฐ์˜ ์›์ ์œผ๋กœ ๋ถ€ํ„ฐ ์ปจํ…์ธ  ๋ทฐ์˜ ์›์ ์ด ์–ด๋Š์ •๋„ ๋–จ์–ด์ ธ ์žˆ๋Š”๊ฐ€?
  • ์ฆ‰, ์Šคํฌ๋กค๋œ ์ง€์ 
  • ์ด ๊ฐ’์ด bounds๋ž‘ ๊ด€๋ จ์ด ์žˆ์„ ์ˆ˜ ๋ฐ–์— ์—†๋‹ค.
  • scrollView.setContentOffset(CGPoint(x: .zero, y: 50), animated: true)
  • scrollView.bounds.y = -50
  • ์œ„ ๋‘๊ฐœ๋Š” ๊ฐ™์€ ๊ฒƒ์ด๋‹ค. ๊ฐ™์€ ํ˜„์ƒ์„ ๋ฌด์—‡์„ ์ฃผ์–ด๋กœ ํ•˜์—ฌ ๊ฐ’์„ ๋งค๊ธฐ๋ƒ์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ํ‘œ๊ธฐ๋˜๋Š” ๊ฒƒ.
    • contentView ์ž…์žฅ์—์„œ Offset ๊ฐ„๊ฒฉ ์–‘์ˆ˜๋กœ ๋งค๊ธฐ๊ธฐ๋ฅผ ๋ฐ”๋žŒ
    • bounds๋Š” ๋‚ด๋ถ€์˜ ์ขŒํ‘œ๊ณ„์˜ ์›์ ์„ ์˜๋ฏธํ•จ
      • ์ขŒํ‘œ๊ณ„์˜ ์œ„์น˜๊ฐ€ ์˜ฌ๋ผ๊ฐ€์•ผ ์ปจํ…์ธ ๋Š” ์ƒ๋Œ€์ ์œผ๋กœ ์•„๋ž˜์— ์œ„์น˜ํ•จ == ์Œ์ˆ˜
    • ํ—ท๊ฐˆ๋ฆฐ๋‹ค๋ฉด Frame & Bounds๋ฅผ ์ฐธ๊ณ ํ•˜์ž.

ContentSize

  • ScrollView๋Š” ๋‹น์—ฐํžˆ ์Šคํฌ๋กคํ•˜๋ ค๊ณ  ์“ฐ๋Š” ๊ฒƒ์ด๋‹ค.
  • ๊ทธ๋ ‡๋‹ค๋ฉด ํ™”๋ฉด์— ๋ณด์ด๋Š” ๊ฒƒ๋ณด๋‹ค ์‹ค์ œ ์ปจํ…์ธ  ์˜์—ญ์ด ๋” ๊ธธ๋‹ค๋Š” ๋ง์ด๋‹ค.
  • ์ด๋Ÿฌํ•œ ์˜์—ญ ์ž์ฒด๋ฅผ ๋‚ด๋ถ€์ ์œผ๋กœ ๊ฐ–๊ณ  ์žˆ์„ ๊ฒƒ์ด๋ฉฐ, ์ด๊ฑธ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด contentSize์ด๋‹ค.

Reference