iOS/๐ŸŽ Documentation

The Role of View Controllers (3) - Overview - View Controller Programming Guide for iOS

woozzang 2021. 1. 14. 01:20
์ถœ์ฒ˜ : Apple Developer Documentation

 

Resource Management

UIViewController๋Š” ๋” ์ด์ƒ ํ•„์š”ํ•˜์ง€ ์•Š์€ ์ž์›์„ ์ž๋™์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ ํ•ด์ œํ•ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์ด๊ฒƒ์„ ์„œ๋ธŒ ํด๋ž˜์‹ฑํ•œ ์ปค์Šคํ…€ ์ฝ”๋“œ์—์„œ, ๊ฐœ๋ฐœ์ž๊ฐ€ ๋ช…์‹œ์ ์œผ๋กœ ์ƒ์„ฑํ•œ ๊ฐ์ฒด๋“ค์€ ๊ทธ๊ฒƒ์„ ๋งŒ๋“  ์‚ฌ๋žŒ์ด ์ง์ ‘ ๊ด€๋ฆฌํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

๊ฐ€์šฉ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์ ์–ด์กŒ์„๋•Œ, UIKit์€ ์•ฑ๋“ค์—๊ฒŒ ํ•„์š”ํ•˜์ง€ ์•Š์€ ๋ฆฌ์†Œ์Šค๋ฅผ free up ( = release = ๋ฉ”๋ชจ๋ฆฌ ํ•ด์ œ )  ํ•  ๊ฒƒ์„ ์š”์ฒญํ•ฉ๋‹ˆ๋‹ค.

๊ฐœ๋ฐœ์ž๊ฐ€ ์ด๊ฒƒ์„ ์ด์šฉํ•ด ๋ฉ”๋ชจ๋ฆฌ ํ•ด์ œ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์€ VC์— didReceiveMemoryWarning ๋ฉ”์†Œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ด ๋ฉ”์†Œ๋“œ์—์„œ ๋” ์ด์ƒ ํ•„์š”ํ•˜์ง€ ์•Š์€ ์ฐธ์กฐ๋ฅผ ์ง€์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์บ์‹ฑ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ง€์šธ ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๊ตฌํ˜„๋งŒ ํ•ด๋†“๊ณ  ์ ˆ๋Œ€ ์ง์ ‘ ํ˜ธ์ถœํ•˜์ง€ ์•Š์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค.
์ด ๋ฉ”์†Œ๋“œ๋Š” ๊ฐ€์šฉ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•œ ์ƒํ™ฉ์—์„œ ์‹œ์Šคํ…œ์ด ์•Œ์•„์„œ ํŒ๋‹จํ•˜์—ฌ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

 

๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•œ ์ƒํ™ฉ์—์„œ ๊ฐ€๋Šฅํ•œ ๋งŽ์€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ•ด์ œํ•˜๋Š” ๊ฒƒ์€ ์•„์ฃผ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ง€๋‚˜์น˜๊ฒŒ ๋งŽ์ด ์ ์œ ํ•˜๋Š” ์•ฑ๋“ค์€ ์‹œ์Šคํ…œ์ด ์ข…๋ฃŒ์‹œ์ผœ๋ฒ„๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.


 

Adaptivity

VC ๋Š” View๋“ค์„ ๊ธฐ๊ธฐ์˜ ํ™”๋ฉด ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ๋ฟŒ๋ ค์ฃผ๋Š” ์—ญํ• ์„ ๋‹ด๋‹นํ•ฉ๋‹ˆ๋‹ค.

์ฆ‰, ๋ชจ๋“  iOS ์•ฑ๋“ค์€ iPad ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค์–‘ํ•œ ์‚ฌ์ด์ฆˆ์˜ iPhone์—์„œ ๋Œ์•„๊ฐ€์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๊ธฐ๋งˆ๋‹ค ๋‹ค๋ฅธ VC๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ํ•˜๋‚˜์˜ VC๊ฐ€ ํ™”๋ฉด์˜ ์š”๊ตฌ์‚ฌํ•ญ์— ๋”ฐ๋ผ View๋“ค์„ ์กฐ์ •ํ•˜๋Š” ๊ฒƒ์ด ๋‚ซ๊ธฐ ๋•Œ์ž…๋‹ˆ๋‹ค.

 

iOS์—์„œ, VC๋Š” coarse-grained change์™€ fine-grained change๋ฅผ ๋‹ค๋ฃจ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Coarse-grained change๋Š” VC์˜ ํŠน์„ฑ(traits) ์ด ๋ฐ”๋€” ๋•Œ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

ํŠน์„ฑ(Traits)์ด๋ž€ ํ™”๋ฉด ์Šค์ผ€์ผ๊ณผ ๊ฐ™์€ ์ „๋ฐ˜์ ์ธ ํ™˜๊ฒฝ์„ ๋‹ด๊ณ  ์žˆ๋Š” ์†์„ฑ (attribute) ๋“ค์ž…๋‹ˆ๋‹ค.

ํŠน์„ฑ์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์š”์†Œ ์ค‘ ๋‘ ๊ฐœ๋Š” ๋ฐ”๋กœ VC ์˜ ๊ฐ€๋กœ ์„ธ๋กœ ์‚ฌ์ด์ฆˆ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค. ์ด ํด๋ž˜์Šค๊ฐ€ ์ฃผ์–ด์ง„ ์ฐจ์›์—์„œ VC์—๊ฒŒ ์ฃผ์–ด์ง„ dimension์„ ์•Œ๋ ค์ค๋‹ˆ๋‹ค.

 

dimension : a measurementof something in a particular direction
์ฆ‰, ํŠน์ • ๋ฐฉํ–ฅ์—์„œ์˜ ๊ฐ€๋กœ ์„ธ๋กœ ์ธก์ •์น˜์ด๋ฏ€๋กœ, ๊ธฐ๊ธฐ๋ฅผ ํšŒ์ „ํ•œ๋‹ค๋ฉด (portrait์—์„œ landscape๋กœ) dimension์€ ๋ฐ”๋€Œ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

size ํด๋ž˜์Šค์˜ ๋ณ€ํ™”์— ๋งž์ถ”์–ด view์˜ ๋ ˆ์ด์•„์›ƒ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์•„๋ž˜ ๊ทธ๋ฆผ์„ ๋ณด๋ฉด horizontal size ํด๋ž˜์Šค๊ฐ€  regular ์ผ๋•Œ, ๊ฐ€๋กœ ์‚ฌ์ด์ฆˆ์˜ ์ด๋“์ด ์žˆ์œผ๋ฏ€๋กœ VC๋Š” ๊ทธ๋งŒํผ ์ฝ˜ํ…์ธ ๋ฅผ ์ฑ„์›Œ ๋„ฃ์Šต๋‹ˆ๋‹ค.

๋ฐ˜๋ฉด์— horizontal size ํด๋ž˜์Šค๊ฐ€ compact ์ผ๋•Œ๋Š”, VC๋Š” ์ฝ˜ํ…์ธ ๋ฅผ ์„ธ๋กœ๋กœ ์ฑ„์›Œ ๋„ฃ์Šต๋‹ˆ๋‹ค.

 

์ƒํ™ฉ์— ๋งž๊ฒŒ VC๊ฐ€ view(๋…น์ƒ‰ ์‚ฌ๊ฐํ˜•)๋“ค์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์„ Adpating ์ด๋ผ๊ณ  ํ‘œํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

์œ„ size ํด๋ž˜์Šค์— ํ›จ์”ฌ ์ž์ฃผ ์ผ์–ด๋‚˜๋Š” ์ƒํ™ฉ์€ fine-grained change์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ iPhone์„ portrait์—์„œ  landscape๋กœ ํšŒ์ „์‹œํ‚ฌ ๋•Œ, size ํด๋ž˜์Šค๋Š” ๋ฐ”๋€Œ์ง€ ์•Š๊ฒ ์ง€๋งŒ, dimension ์€ ๋ฐ”๋€Œ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๊ธฐ์ค€์ด ๋˜๋Š” ๋ฐฉํ–ฅ์ด ๋ฐ”๋€Œ์—ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

 

 

 

๋!