/iOS_Collection_Layout

๐Ÿ“ WWDC ์Šคํ„ฐ๋”” - UI ๊ตฌํ˜„ ์„ธ์…˜ ๋ฐœํ‘œ ์ž๋ฃŒ

Primary LanguageSwift

Advances in Collection View Layout

iOS UIKit UICollectionVIew Flow Layout / Compositional Layout, Texture, FlexLayout ๊ธฐ๋ฐ˜์˜ ๋ ˆ์ด์•„์›ƒ ์‹ค์Šต

Description

  • Flow Layout ๊ธฐ๋ฐ˜ Grid ํ˜•์‹ ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ
  • Flow Layout ๊ธฐ๋ฐ˜ Self-Sizing Cell ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ
  • Compositional Layout ๊ธฐ๋ฐ˜ Self-Sizing Cell ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ
  • Compositional Layout ๊ธฐ๋ฐ˜ nested collectionView ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ
  • Texture ๊ธฐ๋ฐ˜ Masonry ํ˜•์‹์˜ ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ(Pinterest)
  • FlexLayout ๊ธฐ๋ฐ˜ Self-Sizing Feed ํ˜•์‹ ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ

Getting Start

UIKit, SnapKit, PinLayout, FlexLayout, Texture

Issue

1. ๋ณด์ผ๋Ÿฌ ํ”Œ๋ ˆ์ดํŠธ

  • Flow Layout
    • class ๊ธฐ๋ฐ˜์œผ๋กœ ์ปค์Šคํ…€ ๊ตฌ์„ฑํ•˜๊ณ , Item ํฌ๊ธฐ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์„œ๋กœ ๊ฐ„ intersection์„ ํ† ๋Œ€๋กœ main axis์— ๋งž์ถ”์–ด ๋ทฐ๋ฅผ ๊ตฌ์„ฑ
    • ์‹ค์งˆ์ ์œผ๋กœ delegate๋กœ ๊ตฌ์„ฑ์„ ํ•˜๋ฉด์„œ ๊ธฐ๋ฐ˜์— ๊ตฌ์„ฑํ•ด์•ผ ํ•  ์ฝ”๋“œ์˜ ์–‘์ด ๊ฐ€์žฅ ๋งŽ๋‹ค
  • Compositional Layout
    • ๋ถ€๋ถ„์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ „์ฒด๋ฅผ ๊ตฌ์„ฑํ•œ๋‹ค
    • ๋ณ„๋„์˜ ํด๋ž˜์Šค ๊ตฌ์„ฑ ์—†์ด ๊ฐ ์š”์†Œ๋“ค์˜ ํฌ๊ธฐ์™€ feature๋ฅผ ๊ตฌ์„ฑ๊ฐ€๋Šฅํ•˜๋‹ค
    • delegate ๊ตฌ์„ฑ์ด ๋ณ„๋„๋กœ ํ•„์š” ์—†๋‹ค
  • Texture
    • ์ฝœ๋ ‰์…˜ ๋ทฐ ํ™œ์šฉ์— ์žˆ์–ด์„œ๋งŒ์€ FlowLayout๊ณผ ๋ณ„ ๋‹ค๋ฅธ ์ฐจ์ด๊ฐ€ ์—†๋‹ค
    • ํ•˜์ง€๋งŒ ์ปค์Šคํ…€ ๋ทฐ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ์ธก๋ฉด์— ์žˆ์–ด์„œ manual ํ•œ SnapKit ๋“ฑ์˜ ๊ตฌ์„ฑ๊ณผ ๋น„๊ตํ–ˆ์„ ๋•Œ, FlexBox ์š”์†Œ๋ฅผ ํ™œ์šฉ์€ ๊ฐ€๋Šฅํ•˜๋‹ค - ์ ๊ทน์ ์ด์ง„ ์•Š๋‹ค
    • ์ฝ”๋“œ๋Ÿ‰์— ์žˆ์–ด์„œ ํฐ ์ฐจ์ด๋ฅผ ์ฒด๊ฐํ•˜์ง€ ๋ชปํ–ˆ๋‹ค
    • node ๋ณ„๋กœ Component๋ฅผ ๊ตฌ๋ถ„์ง€์–ด ๊ตฌ์„ฑํ•˜๋Š” ์ ์—์„œ ๋งˆ์ดํฌ๋กœ ๋””์ž์ธ ์˜์—ญ์— ์กฐ๊ธˆ ๋” ๋งž์ถฐ์ง„ ๋“ฏ ํ•˜๋‹ค - ์„ ์–ธ์ ์œผ๋กœ ๊ตฌ์„ฑ๋˜์—ˆ๋‹ค๋Š” ์˜๋ฏธ
    • Rx๋ฅผ ๊ฒฐํ•ฉ, Obj-c ๊ธฐ๋ฐ˜์˜ ๋ ˆํผ๋Ÿฐ์Šค ์ฝ”๋“œ๊ฐ€ ๋งŽ๋‹ค
  • FlexLayout
    • ํ™•์‹คํžˆ ์ฝ”๋“œ๋Ÿ‰์ด ๋งค์šฐ ์ ๋‹ค
    • update / init ์‹œ์ ์—์„œ ๋ทฐ์˜ ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ์„ ๋ณด๋‹ค ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ PinLayout์„ ํ™œ์šฉํ•œ๋‹ค๋ฉด ๋” ํŽธ๋ฆฌํ•ด์ง„๋‹ค
    • ์ถ”์ƒํ™”์˜ ๋‹จ๊ณ„๊ฐ€ ์ „ ๋ณด๋‹ค๋Š” ๋†’์•„์ ธ ๊ฐ„๊ฒฐํ•ด์ง„ ์ฝ”๋“œ๊ฐ€ ๋งŽ๋‹ค

2. self-sizing

  • Flow Layout
    • ๊ฐ ์š”์†Œ๋ฅผ ์ˆœํšŒํ•˜๋ฉด์„œ ์ง์ ‘์ ์œผ๋กœ ์‚ฌ์ด์ฆˆ์— ๋Œ€ํ•œ ๊ฐ’์„ ์ฒดํฌํ•˜๊ณ  ๋ทฐ๋ฅผ ์ƒˆ๋กœ ๊ณ ์นจ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค
  • Compositional Layout
    • ํŽธ-๋ฆฌ!, .estmated size์˜ ์†Œ์ค‘ํ•จ์„ ๊นจ๋‹ซ์ž
  • Texture
    • layoutSpecThatFits์˜ ํ™œ์šฉ์œผ๋กœ ๊ทธ๋‚˜๋งˆ ์ ์šฉ ๊ฐ€๋Šฅํ•œ ์ˆ˜์ค€
    • ๋ ˆ์ด์•„์›ƒ๊ณผ ์‚ฌ์ด์ง•์— ์žˆ์–ด์„œ๋Š” ํ™•์‹คํžˆ Container / Item์˜ ๊ฐœ๋…์œผ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์–ด ์šฉ์ดํ•˜๋‹ค
  • FlexLayout
    • update ์‹œ์ ์—์„œ ์ฃผ์ž…๋˜๋Š” ๋ฐ์ดํ„ฐ์— ๋”ฐ๋ผ์„œ flex.markDirty()์˜ ํ˜ธ์ถœ์„ ํ†ตํ•ด์„œ ํ•ด๋‹น ์‚ฌ์ด์ฆˆ์— ๋งž๊ฒŒ ๋™๊ธฐํ™”๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค
    • grow/shirink, justify/asign ๋“ฑ์˜ Container / Item ๊ด€๊ณ„ ์„ค์ •์„ ๋ณด๋‹ค ํ™•์‹คํ•˜๊ฒŒ ํ•˜์—ฌ ๊ตฌ์„ฑ์ด ๊ฐ€๋Šฅํ•˜๋‹ค

3. Flex ๊ฐœ๋…

KeyNote

References