Skip to content

Latest commit

ย 

History

History
287 lines (199 loc) ยท 11.3 KB

High_Performance_Auto_Layout.md

File metadata and controls

287 lines (199 loc) ยท 11.3 KB

High Performance Auto Layout

WWDC ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋ชฉํ‘œ: iOS 12 ์—์„œ ๋ ˆ์ด์•„์›ƒ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ์œ„ํ•ด ์–ด๋–ค ๊ฒƒ์„ ์ œ๊ณตํ• ๊นŒ?

view, constraints๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ ˆ์ด์•„์›ƒ์„ ์„ค์ •ํ•œ๋‹ค.

  • Constrints๋Š” ๋ฌด์—‡์ธ๊ฐ€? ๋ทฐ ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ์ •์˜ํ•œ๋‹ค.

  • ์ง๊ด€(intuition) << analyze(intuition -> practice)

๊ฐœ์„  ์‚ฌํ•ญ ๋ฏธ๋ฆฌ๋ณด๊ธฐ: UICollection์—์„œ self-sizing view

iOS 11์—์„œ๋Š” self-sizing์ด ์ œ๋Œ€๋กœ ์ ์šฉ๋˜์ง€ ์•Š์•˜์ง€๋งŒ 12์—์„œ๋Š” ๊ฐœ์„ ํ–ˆ๋‹ค.

์‹œ๊ฐ„๋„ ๋” ์ ๊ฒŒ ๊ฑธ๋ฆฐ๋‹ค. (ํŒŒ๋ž€์ƒ‰์ด iOS 12, ํšŒ์ƒ‰์ด iOS 11)

๋ฌธ์ œ ์ œ์‹œ

IB๋กœ(Interface Builder => storyboard) ๋ ˆ์ด์•„์›ƒ ์ž‘์„ฑํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž! ์œ„ ๋ ˆ์ด์•„์›ƒ ์„ธํŒ…์€ ์•„๋ฌด๋Ÿฐ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค!

์œ„ ์ฝ”๋“œ์ฒ˜๋Ÿผ ์ž‘์„ฑํ•˜๋ฉด ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค!

  • ๋ฌธ์ œ1: UIView ๋ฉ”์„œ๋“œ์ธ updateConstraints๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•˜๊ณ  ์žˆ๋‹ค.
  • ๋ฌธ์ œ2: ๊ธฐ์กด ๋ ˆ์ด์•„์›ƒ์„ ๋ชจ๋‘ deactivate ์‹œํ‚ค๊ณ  ์ƒˆ๋กœ์šด ์ œ์•ฝ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
    • super.updateConstraints ํ˜ธ์ถœ์€ ๋งค์šฐ ์ค‘์š”

๋จผ์ € updateConstraints๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์•Œ์•„๋ณด์ž!

updateConstraints๋Š” Render loop์˜ ๊ตฌ์„ฑ์š”์†Œ ์ค‘ ํ•˜๋‚˜์ด๋‹ค. Render loop๋Š” ๋ฌด์—‡์ธ๊ฐ€? contents๊ฐ€ ๊ฐ frame์— ์ž˜ ์ž๋ฆฌ ์žก๋„๋ก ์ตœ๋Œ€ ์ดˆ๋‹น 120๋ฒˆ ๋Œ์•„๊ฐˆ ์ˆ˜ ์žˆ๋Š” process์ด๋‹ค. ์ด 3๋‹จ๊ณ„๋กœ ์ด๋ค„์ ธ์žˆ๋‹ค.(Update Constraints, Layout, Display)

  1. Update Constraints
  • ๋จผ์ € ๋ชจ๋“  view๋Š” updateConstraints๋ฅผ ๋ฐ›๋Š”๋‹ค.(receive)
  • view ๊ณ„์ธต ํ•˜๋‹จ์—์„œ(leaf) ๋ถ€๋ชจ๋กœ(window)
  1. layout
  • layout์„ ํ˜ธ์ถœ
  • window์—์„œ leaf๋กœ
  1. Display
  • draw ํ˜ธ์ถœ
  • window์—์„œ leaf๋กœ

์™œ ์ด๋ ‡๊ฒŒ ํ•˜๋‚˜?

์“ธ๋ฐ์—†๋Š” ์ผ์„ ํ•˜์ง€ ์•Š๋„๋ก(avoid wasted work)

์˜ˆ๋ฅผ ๋“ค์–ด๋ณด์ž

UILabel์€ text size๊ฐ€ ํ•„์š”ํ•˜๋‹ค. text property, font, text size ๋“ฑ์ด ์žˆ๋‹ค. ํ•˜๋‚˜์˜ ๋ฐฉ๋ฒ•: ํ•˜๋‚˜์˜ ํ”„๋กœํผํ‹ฐ๋ผ๋„ ๋ณ€๊ฒฝ๋˜๋ฉด ๋‹ค์‹œ ์ธก์ •(measure)ํ•ด์„œ ํ™•์ธํ•œ๋‹ค. ํ•˜์ง€๋งŒ, ์œ„ ๋ฐฉ๋ฒ•์€ ๋ณดํ†ต ๋น„ํšจ์œจ์ ์ด๋‹ค.(์ด์œ : ์ˆœ์ฐจ์ ์œผ๋กœ ๋‹ค ๋ถˆ๋ฆด ๊ฒƒ์ด๋‹ค.) ํ•ด๊ฒฐ: setNeedsUpdateConstraints ํ˜ธ์ถœํ•˜์ž -> frame์ด screen์œผ๋กœ ๊ฐ€๊ธฐ ์ „ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์— constraints๋ฅผ ๊ฐฑ์‹ ํ•  ๊ฒƒ์„ ๋ณด์žฅํ•œ๋‹ค.

"์™œ ์ด๋ ‡๊ฒŒ ํ•˜๋‚˜? ์ •๋ฆฌ

render loop๋Š” ๋„ˆ๋ฌด ๋งŽ์ด ๋ฐ˜๋ณต(120๋ฒˆ/s) ๋ฉ”์„œ๋“œ๋“ค์ด ๋ณ‘๋ ฌ์ ์œผ๋กœ ๋™์ž‘ํ•œ๋‹ค.

๋‹ค์‹œ ๋ฌธ์ œ๋กœ ๋Œ์•„์™€์„œ ํ•ด๊ฒฐํ•˜์ž

๋ชจ๋“  ๋ ˆ์ด์•„์›ƒ์„ deactivateํ•˜๊ณ  activateํ•˜๋Š” ๊ฒƒ(= churning the constaints)์˜ ๋ฌธ์ œ๊ฐ€ ๋ญ˜๊นŒ?

๋ชจ๋“  subviews๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๋‹ค์‹œ subviews๋ฅผ ๋„ฃ๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•˜๋‹ค. => ์ฆ‰, ์„ฑ๋Šฅ์— ๋‚˜์˜๋‹ค

๋งˆ์ง€๋ง‰์— ๋”ฑ ํ•œ๋ฒˆ๋งŒ ํ•˜๋„๋ก ์ˆ˜์ •ํ•˜์ž

render loop๋กœ ๋ถˆํ•„์š”ํ•œ ์ผ์„ ํ•˜์ง€ ์•Š์•„์„œ ์ข‹์ง€๋งŒ "๋„ˆ๋ฌด ์ž์ฃผ ๋™์ž‘ํ•˜๋Š” ์ฝ”๋“œ"๋ผ์„œ ์„ธ๋ฐ€ํ•˜๊ฒŒ ๋‹ค๋ค„์•ผํ•œ๋‹ค.

IB๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์•Œ์•„์„œ ํ•ด์ฃผ๊ธฐ ๋–„๋ฌธ์— ์‹ ๊ฒฝ์“ธ ํ•„์š”๊ฐ€ ์—†๋‹ค!

constraints๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด("activate") ๋‚ด๋ถ€์ ์œผ๋กœ ๋ฌด์Šจ์ผ์ด ์ผ์–ด๋‚˜๋Š”์ง€ ์•Œ์•„๋ณด์ž

๋ ˆ์ด์•„์›ƒ์„ ์„ค์ •ํ•˜๋ ค๋Š” view๊ฐ€ ์žˆ๋‹ค. view๋Š” window์— ์žˆ๋‹ค. window๋Š” engine์„ ๊ฐ€์ง„๋‹ค. engine์€ autolayout์˜ ํ•ต์‹ฌ์ด๋‹ค view์—์„œ constraints๋ฅผ ๋งŒ๋“ค๋ฉด equation์ด ์ƒ์„ฑ๋œ๋‹ค. equation๋Š” engine์— ์ถ”๊ฐ€๋œ๋‹ค. equation๋Š” variable๊ณผ ๊ด€๋ จ๋˜์–ด ์žˆ๋‹ค.

ex. equation์—์„œ x๊ฐ€ ๋ญ”์ง€ ์•Œ๋ ค๋‹ฌ๋ผ๊ณ  ํ•˜๋ฉด view์˜ freme ๋ฐ์ดํ„ฐ๋ฅผ ์•Œ์•„์•ผํ•œ๋‹ค. frame์—๋Š” minX, minY, width, height๊ฐ€ ์žˆ๋‹ค.

๊ฐ„๋‹จํžˆ ์‚ดํŽด๋ณด๊ธฐ ์œ„ํ•ด ์ˆ˜ํ‰ ๋ ˆ์ด์•„์›ƒ๋งŒ ์‚ดํŽด๋ณด์ž!

๋จผ์ €, equation์„ ๋งŒ๋“ ๋‹ค. ๋‘ view ๊ฐ„์˜ ๊ฐ„๊ฒฉ์— ๋Œ€ํ•œ equation์ด ์ด์ƒํ•ด ๋ณด์ผ ์ˆ˜ ์žˆ์ง€๋งŒ, variable๊ด€์ ์—์„œ์˜ ๋ฐฉ์ •์‹์ด๋‹ค!

์ด์ œ ๊ฐ equation์€ engine์— ์ถ”๊ฐ€๋ผ์•ผํ•œ๋‹ค. engine์€ variable์„ ํ’€๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•œ๋‹ค.

engine ๋‚ด๋ถ€๋ฅผ ์‚ดํŽด๋ณด์ž

variable์„ ํ‘œํ•จํ•œ equation์˜ ๊ฒฝ์šฐ subtitutes๋ฅผ ์ฐพ์•„์„œ ๊ฐ’์„ ์ฐพ์•„๋‚ธ๋‹ค. ์ฆ‰, ์•„๋ž˜์ฒ˜๋Ÿผ ์น˜ํ™˜๋œ๋‹ค.

=> engine์—์„œ variable ํ•ด์„ํ•˜๋Š” ๊ฒƒ์€ ์ด์ œ ๋๋‚ฌ๋‹ค.(layout์€ ์•„์ง ์•„๋‹ˆ๋‹ค.)

์ด์ œ ์•Œ๊ฒŒ๋œ variable์„ ๊ฐ€์ง€๊ณ  process๋ฅผ ๋๋‚ด๋ณด์ž!

์ด๋•Œ๊นŒ์ง€๋Š” upateConstraints ๋‹จ๊ณ„์—์„œ ์ผ์–ด๋‚˜๋Š” ์ผ! ์—”์ง„ ๋‚ด๋ถ€์—์„œ variabe์ด ๋ญ”์ง€ ์•Œ๋ฉด view์—๊ฒŒ ๊ฐ’์ด ๋ฐ”๋€Œ์—ˆ๋‹ค๊ณ  ์•Œ๋ฆฐ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด view๋Š” superview์˜ setNeedsLayout()์„ ํ˜ธ์ถœํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ๋‚˜์ค‘์— layout ๋‹จ๊ณ„๋กœ ์ด๋™ํ•œ๋‹ค.

engine์—์„œ ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋“ค(์œ„์—์„œ ๊ณ„์‚ฐํ•ด์„œ ์–ป์€ ๊ฐ’๋“ค)์„ frame์— ๋ณต์‚ฌํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด subView๋Š” setBounds(), setCenter()๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค. ๋ ˆ์ด์•„์›ƒ ํ”„๋กœ์„ธ์Šค ๋!

์œ„ ๋ฌธ์ œ๋กœ ๋‹ค์‹œ ๋Œ์•„๊ฐ€์ž

churning!(์“ธ๋ฐ์—†์ด ๊ฐ™์€ ์—ฐ์‚ฐ ๋ฐ˜๋ณต) ๊ฐœ๋ณ„์ ์ธ process๋Š” ๊ฐ„๋‹จํ•˜์ง€๋งŒ ๋ถˆํ•„์š”ํ•œ ๋™์ผํ•œ ์ž‘์—…์ด ๋งค๋ฒˆ ๋ฐ˜๋ณต๋œ๋‹ค.

๋ทฐ๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ๋ฌธ์ œ๋ฅผ ๋‹ค์‹œ ์‚ดํŽด๋ณด์ž

์ด์ œ ๋ทฐ๊ฐ€ 4๊ฐœ์ธ ์ƒํ™ฉ ๋™์ผํ•œ superView๊ฐ€ ์—†๋Š”๋ฐ ์ƒ๋Œ€์ ์ธ constraints ์„ค์ • -> ์„ฑ๋Šฅ์ƒ ๋‚˜์˜๋‹ค.

์ผ๋ฐ˜์ ์ธ ๊ฒฝ์šฐ๋Š” ๋ถ€๋ชจ, ์ž์‹ ์‚ฌ์ด์—๋งŒ ์ œ์•ฝ์„ ์„ค์ •ํ•œ๋‹ค.

2๊ฐœ์˜ ๋…๋ฆฝ์ ์ธ engine์„ ํ˜•์„ฑํ•œ๋‹ค. ๋…๋ฆฝ์ ์œผ๋กœ equation์„ ๊ณ„์‚ฐํ•œ๋‹ค. variable๋„ ๊ฒน์น˜๋Š” ๊ฒƒ(overlap)์ด ์—†๊ณ , ์ƒํ˜ธ์ž‘์šฉ(interact)๋„ ํ•˜์ง€ ์•Š๋Š”๋‹ค.

์„œ๋กœ ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์ด ์—†์œผ๋ฉด(์˜์กด์„ฑ์ด ์—†์–ด์„œ) ์ƒํ˜ธ์ž‘์šฉํ•˜์ง€ ์•Š์•„์„œ, linearํ•˜๊ฒŒ ์„ฑ๋Šฅ์— ์˜ํ–ฅ์„ ๋ฏธ์นจ ์ฆ‰, 2๊ฐœ๋ฉด 2๋ฐฐ๋กœ ๊ฑธ๋ฆฌ๋Š” ๊ฒƒ! 3๊ฐœ๋ฉด 3๋ฐฐ!...

๋ ˆ์ด์•„์›ƒ ์—”์ง„์€ ํŠน์ • ๋ ˆ์ด์•„์›ƒ์„ ์—…๋ฐ์ดํŠธํ•˜๋ฉด ๋”ฑ ํ•„์š”ํ•œ ๊ฒƒ๋งŒ ์—…๋ฐ์ดํŠธํ•œ๋‹ค.

์ œ์•ฝ ์„ค์ •์„ ์ค„์ด๋ ค๋Š” ๋…ธ๋ ฅ์„ ํ•˜์ง€ ๋ง๋ผ, ์˜๋ฏธ์—†๋‹ค. ํ•„์š”ํ•œ ์ œ์•ฝ์„ ๊ทธ์ € ์„ธํŒ…ํ•˜๋ฉด ๋จ

2๊ฐœ์˜ ์ œ์•ฝ์กฐ๊ฑด์„ ํ•˜๋‚˜๋กœ ํ‘œํ˜„ํ•˜๋‹ค๋ณด๋‹ˆ ์ „์ฒด์ ์œผ๋กœ ๋ถˆ๋ช…ํ™•ํ•˜๊ณ  ๋ณต์žกํ•œ ์ œ์•ฝ์ด ๊ตฌ์„ฑ๋œ ์ƒํƒœ ์šฐ์„ ์ˆœ์œ„๋„์— ๋”ฐ๋ผ ์—ฌ๋Ÿฌ ๋ ˆ์ด์•„์›ƒ์„ ์„ค์ •ํ•œ ์ƒํƒœ ์ด๊ฒƒ๋„ ์ข‹์€ ์ƒ๊ฐ์€ ์•„๋‹ˆ๋‹ค. ๊ฐ€์งœ ์˜์กด์„ฑ์„ ๋งŒ๋“ค๊ฒŒ ๋˜๋Š”๋ฐ, ๋„ค๊ฐ€ ๋ ˆ์ด์•„์›ƒ ์˜ค๋ฅ˜๋ฅผ ๋ฐœ๊ฒฌ ๋ชปํ•˜๋ฉด debug๋„ ์•Œ๋ ค์ฃผ์ง€ ๋ชปํ•œ๋‹ค.

๊ฒฐ๋ก : ์ตœ๋Œ€ํ•œ ์ง๊ด€์ ์œผ๋กœ(directly) ์ œ์•ฝ์„ ์„ค์ •ํ•˜๋ผ natural way๋กœ ์ œ์•ฝ์„ ์„ค์ •ํ•˜๋ผ! ๊ทธ๋ž˜์•ผ ํผํฌ๋จผ์Šค์—๋„ ์ข‹๊ณ , ์ดํ•ดํ•˜๊ธฐ๋„ ์‰ฝ๋‹ค.

๋‹ค๋ฅธ ๊ฒƒ๋“ค์— ๋Œ€ํ•œ ์„ฑ๋Šฅ๋„ ์•Œ์•„๋ณด์ž

inequality(์ดํ•˜, ์ด์ƒ)

๋™๋“ฑ ๋น„๊ต์™€ ์ฐจ์ด๊ฐ€ ์—†๋‹ค. ์ •ํ™•ํ•˜๊ฒŒ๋Š” one more variable์˜ ์ฐจ์ด

set constant

engine์ด dependancy tracker๋ผ์„œ performance ์ตœ์ ํ™”๋กœ ๋ ˆ์ด์•„์›ƒ์„ ์ž์ฃผ ๋ฐ”๊ฟ”๋„ ์‹ ์†ํžˆ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋œ๋‹ค.

priority

์ด๊ฑด ์œ„์— ๊ฒƒ๋“ค๊ณผ ๋‹ค๋ฅด๊ฒŒ ์กฐ๊ธˆ ๋” cost๊ฐ€ ๋“ ๋‹ค. priority๋ฅผ ๋ถ€์—ฌํ•˜๋Š” ๊ฒƒ์€ ํŠน์ • ์‚ฌ์ด์ฆˆ + error๋ฅผ ์š”์ฒญํ•˜๋˜ error ๋ฅผ ์ตœ์†Œํ™”ํ•˜๋ผ๊ณ  ํ•˜๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•˜๋‹ค. ์ฆ‰, error ์ตœ์†Œํ™”ํ•˜๋Š” ๋‹จ๊ณ„๊ฐ€ ์ถ”๊ฐ€์ ์œผ๋กœ ํ•„์š”ํ•œ ๊ฒƒ์ด๋‹ค.

์ •๋ฆฌ

๋ ˆ์ด์•„์›ƒ์ด ๋ฐ˜๋ณต์ ์œผ๋กœ ์„ธํŒ…๋˜์ง€ ์•Š๋„๋กํ•˜๋ผ(nil ํ™•์ธ) ๋ ˆ์ด์•„์›ƒ ๊ณ„์‚ฐ์€ ๊ฐ„๋‹จํ•˜๋‹ค. Auto layout์€ layout์„ ์œ„ํ•œ cache์ด๋‹ค. ์ฆ‰, engine์€ ๊ณ„์‚ฐ๋œ ๊ฐ’๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ  dependency tracker๋ผ์„œ ์–ด๋–ค ๊ฐ’์ด ๋ฐ”๋€Œ๋ฉด ๋”ฑ ๋ฐ”๊ฟ”์•ผํ•  ๊ฒƒ๋“ค๋งŒ ๋ณ€๊ฒฝ(super targeted way)

intuition to practice(analyze)

์ง๊ด€๋งŒ ๋ฏฟ๊ณ  ๋ ˆ์ด์•„์›ƒ์„ ์ž‘์„ฑํ•˜๋ฉด ์„ฑ๋Šฅ์— ๋‚˜์ ์ˆ˜๋„...

tableViewCell ์˜ˆ์‹œ๋กœ ๋ณต์žกํ•œ ๋ ˆ์ด์•„์›ƒ ๊ตฌ์„ฑ์„ ์ž˜ ์„ค์ •ํ•˜๋Š” ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž

4๊ฐœ์˜ ๋น„์Šทํ•œ ๋ ˆ์ด์•„์›ƒ์„ ๊ตฌ์„ฑํ•ด์•ผํ•˜๋Š” ์ƒํ™ฉ

-> scroll performance๊ฐ€ ์ข‹์ง€ ๋ชปํ•˜๋‹ค.

performance๋ฅผ ์ž์„ธํžˆ ์‚ดํŽด๋ณด์ž

์‚ฌ์šฉ๋˜๋Š” CPU ๊ฐœ์ˆ˜๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋‹ค. peak์ด ๋†’์œผ๋ฉด ์„ฑ๋Šฅ์ด ์ข‹์ง€ ์•Š์€ ๊ฒƒ ์–ผ๋งˆ๋‚˜ ๋งŽ์€ view๊ฐ€ ์˜ํ–ฅ์„ ๋ฐ›๊ณ  ์žˆ๋Š”์ง€๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

์—ฌ๋Ÿฌ peak์ด ์žˆ์ง€๋งŒ churning์ด ์œ ๋… ๋†’์€ ๊ฒƒ์„ ์‚ดํŽด๋ณด์ž

detailView๋ฅผ ์‚ดํŽด๋ณด๋Š” ๊ฒƒ

label 3๊ฐœ๊ฐ€ churn ๋˜๋Š” ์ค‘์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

์ง€๊ธˆ์€ ์–ด๋–ค ์ƒํ™ฉ์ด๋ƒ๋ฉด

updateConstraints๊ฐ€ override ๋œ ์ƒํƒœ์ด๋‹ค. ๋ ˆ์ด์•„์›ƒ์ด ๋ฐ”๋€Œ๋ฉด ๋ชจ๋“  view์˜ ๋ ˆ์ด์•„์›ƒ์„ ์ œ๊ฑฐํ–ˆ๋‹ค๊ฐ€ ๋‹ค์‹œ ๋ฐฐ์น˜์‹œ์ผœ์„œ ๋ฐœ์ƒํ•˜๋Š” ์„ฑ๋Šฅ์  issue

์œ„ ์ƒํƒœ๋Š” ๋ชจ๋“  ๋ ˆ์ด์•„์›ƒ์ด ์—†์–ด์ง„ ์ƒํƒœ

hidden์œผ๋กœ ๋ ˆ์ด์•„์›ƒ issue ์ค„์—ฌ๋ณด์ž

๊ธฐ์กด ๋ ˆ์ด์•„์›ƒ์—์„œ ํ•˜๋‚˜์˜ ๋ทฐ์— ๋Œ€ํ•œ interaction -> ๋ชจ๋“  ๋ทฐ ๋ ˆ์ด์•„์›ƒ์„ ์—†์•จ ํ•„์š”๊ฐ€ ์žˆ์„๊นŒ?

hidden์œผ๋กœ ์ฒ˜๋ฆฌํ•˜์ž(view ๊ณ„์ธต์—์„œ ํ•ด๋‹น view๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์ˆจ๊ธฐ๋Š” ๊ฒƒ์ด ํ›จ์”ฌ cheap)

ํŠน์ • ์ œ์•ฝ๋งŒ ํ™œ์„ฑํ™”, ๋น„ํ™œ์„ฑํ™”

๋ชจ๋“  ๋ทฐ๊ฐ€ ๊ธฐ์กด๊ณผ ๊ฐ™์€ ์œ„์น˜์— ์žˆ๋Š”๋ฐ๋„ ๋™์ผํ•œ ์—ฐ์‚ฐ์„ ์ง„ํ–‰ํ•˜๊ธฐ ๋•Œ๋ฌธ์— churn์ด ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ!

์ดˆ๋ก์ƒ‰ ์„ ์€ ๊ธฐ์กด์ด๋ž‘ ๋™์ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฑด๋“œ๋ฆฌ๋ฆฌ ๋ง์ž

๋…ธ๋ž€์ƒ‰์„ deactivateํ•˜๊ณ  ๋นจ๊ฐ„์ƒ‰์„ activate

UILabel์ด ๋ณธ์ธ size ๊ณ„์‚ฐํ•  ๋•Œ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์ด ์–ด๋–ป๊ฒŒ ๋˜๋Š”์ง€ ์•Œ์•„๋ณด์ž

UIImageView๋Š” ๋‚ด๋ถ€์˜ image ์‚ฌ์ด์ฆˆ๋ฅผ ํ†ตํ•ด intrinsic content size๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค. UILabel์€ text๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

text measurement๊ฐ€ ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋Š” ๊ฒฝ์šฐ๋Š” overridingํ•˜๋Š” ๊ฒƒ์ด ๋” ๋น ๋ฅด๋‹ค. ์œ„ ์ฝ”๋“œ๋Š” text measurement๊ฐ€ ์—†์ด ๋ถ€๋ชจ view์—๊ฒŒ size๋ฅผ ์•Œ๋ ค์ฃผ๋ฉด์„œ ์„ฑ๋Šฅ์„ ๋†’์ด๋Š” ๋ฐฉ๋ฒ•

Intrinsic content size vs system layout size fitting size

์ „์ž๋Š” engine ์•ˆ์— ๊ฐ’์„ ๋„ฃ์„ ๋•Œ ํ›„์ž๋Š” engine์—์„œ size information์„ ๊บผ๋‚ผ ๋•Œ ์‚ฌ์šฉ ๋‘˜์€ ๋ฐ˜๋Œ€ ๊ฐœ๋…! => ํ›„์ž๋Š” ์‚ฌ์šฉํ•  ์ผ์ด ์ž˜ ์—†์ง€๋งŒ ์„ฑ๋Šฅ์ƒ ์ข‹์ง€ ์•Š์•„์„œ ์กฐ์‹ฌํ•ด์•ผํ•œ๋‹ค.

์™œ ์ข‹์ง€ ์•Š์„๊นŒ?

system layout size fitting size ํ˜ธ์ถœํ•  ๋•Œ๋งˆ๋‹ค engine์ด ์ƒ์„ฑ๋˜๊ณ  ์—†์–ด์ง„๋‹ค. self-sizing collection ์ด๋‚˜ table view cell์—์„œ content view๋กœ ํ˜ธ์ถœํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ์ด๋Ÿฌ๋ฉด scrolling ์ตœ์ ํ™”๋ฅผ ๋ฌด์‹œํ•˜๊ณ  ๋”ฐ๋กœ overridingํ•˜๋Š” ๊ฑฐ + ์ถ”๊ฐ€์ ์ธ engine์„ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด๋ผ ์„ฑ๋Šฅ์—๋Š” ์ข‹์ง€ ์•Š๋‹ค.

์ฐธ๊ณ : instruments -> ์„ฑ๋Šฅ ํ™•์ธ tool ๊ด€๋ จ ๋งํฌ