1. ๐ AutoLayout : Graph_Animated
1.0.1. ๊ทธ๋ํ๋ฅผ ํํํ๋ ๋ฐฉ๋ฒ๊ณผ ์ ๋๋ฉ์ด์

์ค์์ ๋ณด์ด๋ ๋ง๋ํ Graph Layout์ ๋ง๋ค์ด๋ณด๋๊ฒ์ด๋ค.

View ์์ View๋ฅผ ์ถ๊ฐํ์ฌ ๋ง๋๋ฅผ ๋ง๋ค๊ณ
๋ง๋ ํ๋๋ฅผ ์ฐํด๋ฆญํ์ฌ ์์View์ 'Equals Height' ์ค์ ํ๊ณ
Structure์ ๋ณด์ด๋ฏ์ด ์์ View ~ ๋ง๋ View 6๊ฐ๋ฅผ ๋ชจ๋ ์ ํํ์ฌ 'Equal Height' ์ค์

6๊ฐ ๋ง๋View๋ง ์ ํํ์ฌ Equal Widths๋ก ๋์ด๋ฅผ ๊ฐ๊ฒ ๋ง๋ค์ด์ค๋ค.

ํ๋ํ๋์ ๋ง๋ View์ ๋์ด๋
Equal Height to ์ Multiplier๋ฅผ ์กฐ์ ํด์ค๋ค.
ํ์ง๋ง ์ฌ๊ธฐ๊น์ง๋ Multiplier๋ฅผ ์ด์ฉํด์ ๊ตฌํํ ๊ฒ์ด์ง๋ง,
์ฌ์ฉ์ํํ ์ ๋ ฅ์ ๋ฐ๊ฑฐ๋ ๋คํธ์ํฌ๋ฅผ ํตํด์ ์ ๋ ฅ๋ฐ์ ๊ฐ์ผ๋ก ํํํ๊ธฐ์ํด์
์ด๊ฒ์ ์ฝ๋๋ก ๊ตฌํํด์ผ ํ๋ค.
์ด๋ฌํ AutoLayout์ ์ด๋ป๊ฒ ๊ตฌํํด์ผ ํ ๊น ?

๊ฐ ๋ง๋View์ Height ์์ฑ์ Outlet์ผ๋ก ์ง์ ํด์ค๋ค.
( Outlet ๋ช : graph1~6Height )

๋ณด๊ธฐ์ ๊ฐ์ด constant, priority ์ ๊ฐ์ ์์ฑ์ ์ฝ๋์์ ๋ฐ๋ก ์ ๋ ฅ๋ฐ์ ์ ์์ง๋ง,
๋น์จ์ธ Multiplier๋ ๋ฐ๋ก ์ ๋ ฅ๋ฐ์ ์ ์๋ค.
๋๋ฌธ์ ์๋ก์ด Constraint ์์ฒด๋ฅผ ๋ง๋ค์ด์ค์ผํ๋ค.

์ดํ viewDidload() ์์ ์ ์ฉ์์ผ์ฃผ๋ฉด ๋๋ค.



์ดํ, ๋ฒํผ ํด๋ฆญ์ ๋ฒํผ๋ง๋ค ๋ง๋ ๊ทธ๋ํ๊ฐ ๋ฐ๋๊ฒ ํ๊ณ ์ถ๋ค๋ฉด ?
Button์ ์ถ๊ฐํ ๋ค์ ์ฝ๋๋ฅผ ์กฐ๊ธ๋ง ์ถ๊ฐํด์ฃผ๋ฉด ๋๋ค.

์ฒซ๋ฒ์งธ๋ก changeConstraint ๋ฉ์๋์ ๋ง์ง๋ง(70 Line)์
return newConstraint ๋ฅผ ์ถ๊ฐํด์ค๋ค.
์ด๋ ์๋ก์ด newConstraint๊ฐ์ ๊ณ์ ๋ฐํ์์ผ์ฃผ๊ธฐ์ํจ์ด๋ค.

์ดํ ์คํ ๋ฆฌ๋ณด๋์ ๋ฒํผ 2๊ฐ๋ฅผ ์ถ๊ฐํ์ฌ IBAction์ ๋ง๋ค๊ณ ๋์,
viewDidLoad()์ ์ป๋ ์ฝ๋๋ฅผ ์ฎ๊ฒจ์ค๋ค.
์ฝ๋๊ฐ ์ฝ๊ฐ ๋ฐ๊ผ๋๋ฐ,
ํด๋น์ฝ๋๋ ์์์ ๊ฐ์ฅ ์ต๊ทผ์ ์ฌ์ฉํ๋ ๊ฐ์ deactive ํ๊ณ ์๋ก active๋ฐ์์
ํญ์ ์๋กญ๊ฒ ํ์ฌ ์ถฉ๋๋์ง ์๊ฒ ํ๋ ๊ฒ์ด๋ค. ( ๊ณ์ return ๋ฐ์ )
์ดํ ๊ทธ๋ํ์ ๋ณํ๊ฐ ๋ณด์ด๊ฒ animation ํจ๊ณผ๋ฅผ ์ฃผ๋ฉด ๋ ์์ฐ์ค๋ฝ๊ฒ ๋ฐ๋๋ค.

layout.IfNeeded()
withDuration 0.5 -> 0.5์ด๋์ ์ค์๊ฐ์ผ๋ก layout์ ์ ์ฉ์์ผ๋ผ ๋ผ๋๊ฒ์ด๋ค.
๐ก layout.IfNeeded()
1. layoutIfNeeded()๊ฐ ํธ์ถ๋๋ฉด, UI๋ฅผ ์ ๋ฐ์ดํธ ํ๋ผ๋ queue์ ๋ท์ชฝ์ ๋ฃ๋๊ฒ์ด ์๋๋ผ, ๋งจ ์์ชฝ์ ๋ฃ์ด์ ๊ณง๋ฐ๋ก UI๊ฐ ๋ณ๊ฒฝ๋๊ธฐ๋ฅผ ๊ธฐ๋ํ ์์๋ ๋ฉ์๋
2. ํด๋น ๋ฉ์๋๊ฐ ํธ์ถ๋๋ฉด Update Cycle์ ๋ฐ๋ก ์คํํ์ฌ ๋ ์ด์์์ด ์ฆ๊ฐ์ ์ผ๋ก ์ ์ฉ
3. layoutSubviews()๋ ๋ด๋ถ ์๊ณ ๋ฆฌ์ฆ์ ์ํด ์ต์ ํ๋์ด ์๊ธฐ๋๋ฌธ์ ๋ช ์์ ์ผ๋ก ๋ถ๋ฆฌ๋ฉด ์๋๋ฏ๋ก ์ ํ์์๋ layoutIfNeeds() ์ฝ๋๋ฅผ ํตํด layoutSubviews() ๋ฉ์๋๊ฐ ๊ฐ์ ์ ์ผ๋ก ๋น ๋ฅด๊ฒ ๋ถ๋ฆฌ๋๋ก ์ค๊ณ
์์ฑ ๊ฒฐ๊ณผ
'๐ iOS > UIKit' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS] AutoLayout : TableView_Expand (0) | 2023.04.04 |
---|---|
[iOS]AutoLayout : pop up _ animation (0) | 2023.04.02 |
[iOS] AutoLayout : Dynamic Text ( ๋์ ํ ์คํธ ) (0) | 2023.03.30 |
[iOS] AutoLayout : StackView ํ์ฉ (0) | 2023.03.30 |
[iOS] reloadData ๊ฐ์ ๋ฐ ์ฐธ๊ณ ์ฌํญ (0) | 2023.03.25 |