ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๐Ÿ‘‰ ๋‚ด์šฉ

  • dimming view ์˜ alpha ๊ฐ’์„ ์ˆ˜์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
  • ๊ฒฐ๊ณผ์ ์œผ๋กœ alpha ๊ฐ’์„ ์›ํ•˜๋Š”๋Œ€๋กœ ์ˆ˜์ •ํ•˜์ง€ ๋ชปํ–ˆ๊ณ , ๋ทฐ ๊ณ„์ธต์˜ ์ ‘๊ทผ๋ฐฉ๋ฒ•๊ณผ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๊ณ ๋ฏผํ•œ ๊ณผ์ •์„ ๊ธ€๋กœ์จ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๐Ÿ‘‰ dimming view alpha ์ˆ˜์ •

์šฐ์„ , ๊ฐœ๋ฐœ์ž ๋ฌธ์„œ์—์„œ๋Š” alpha ์— ๋Œ€ํ•œ ์•ˆ๋‚ด๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— view ์— ์ ‘๊ทผํ•ด์„œ ํ”„๋กœํผํ‹ฐ๋ฅผ ์ˆ˜์ •ํ•ด๋ณด๊ธฐ ์œ„ํ•ด view hierarchy ๋ฅผ ํ™•์ธํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

11

view hierarchy ๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด background alpha ๊ธฐ๋ณธ๊ฐ’์€ 0.2 ๋กœ ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ์ˆ˜์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

UIDimmingView ์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ

UIWindowScene > UIWindow > UITransitionView > UIDimmingView ์ธ ๊ฒƒ์„ ์•Œ์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ์˜ ์ฝ”๋“œ๋กœ ์ ‘๊ทผํ•ด์„œ ์†์„ฑ์„ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

// โœ… UIWindowScene > UIWindow > UITransitionView > UIDimmingView
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
let windows = windowScene?.windows.first?.subviews

print(windows)
// Optional([<UITransitionView: 0x117f1b160; frame = (0 0; 393 852); autoresize = W+H; layer = <CALayer: 0x600000278560>>, <UITransitionView: 0x117f33140; frame = (0 0; 393 852); autoresize = W+H; layer = <CALayer: 0x6000002d2d40>>, <UITransitionView: 0x11748eed0; frame = (0 0; 393 852); autoresize = W+H; layer = <CALayer: 0x600000334b00>>])

view hierachy ์— ํ‘œ์‹œ๋œ ๋Œ€๋กœ ์„ธ ๊ฐœ์˜ UITransitionView ์ค‘ ๋งˆ์ง€๋ง‰์˜ UIDimmingView ์— ์ ‘๊ทผํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

12
// โœ… UIWindowScene > UIWindow > UITransitionView > UIDimmingView
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
let transitionView = windowScene?.windows.first?.subviews[2]
let dimmingView = transitionView?.subviews[0]

dimmingView?.alpha = 0.8

print(transitionView?.subviews)
// Optional([<UIDimmingView: 0x11ad97b60; frame = (-393 -852; 1179 2556); alpha = 0.8; opaque = NO; gestureRecognizers = <NSArray: 0x600000ecf840>; backgroundColor = UIExtendedSRGBColorSpace 0 0 0 0.2; layer = <CALayer: 0x60000031b8a0>>, <UIDropShadowView: 0x11ada0260; frame = (0 548; 393 304); gestureRecognizers = <NSArray: 0x600000e8c270>; layer = <CALayer: 0x600000336200>>])

UIDimmingView ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

๋‹ค์Œ๊ณผ ๊ฐ™์ด view ์ž์ฒด๋ฅผ 0.8 ๋กœ ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ background ์˜ alpha ๊ฐ’์ด 0.2์ด๊ธฐ ๋•Œ๋ฌธ์— ์˜๋„ํ•œ UI ๊ฐ€ ์•„๋‹ˆ์ง€๋งŒ ์ˆ˜์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

13

์ด๋ฒˆ์—๋Š” background ์ƒ‰์ƒ์— ๊ฒ€์ •์ƒ‰์— alpha ๊ฐ’์„ 0.4 ์ฃผ์–ด์„œ ์ˆ˜์ •ํ•˜์—ฌ ์˜๋„ํ•œ UI ๊ฐ€ ์™„์„ฑ๋˜๋„๋ก ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
let transitionView = windowScene?.windows.first?.subviews[2]
let dimmingView = transitionView?.subviews[0]
dimmingView?.backgroundColor = .black.withAlphaComponent(0.4)
14

ํ•˜์ง€๋งŒ, ์ด๋Ÿฐ์‹์˜ ์ ‘๊ทผ์„ ์œ„ํ•ด์„œ๋Š” viewDidLoad ์—์„œ ํ˜ธ์ถœํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น ๋ผ์ดํ”„ ์‚ฌ์ดํด๊นŒ์ง€๋Š” ๋‹น์—ฐํžˆ ๋ทฐ๊ฐ€ ์•„์ง ๊ทธ๋ ค์ง€๊ธฐ ์ „์ด๋‹ˆ UITransitionView ๊ฐ€ ๋‘ ๊ฐœ๋งŒ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ viewWillAppear ๋‹จ๊ณ„ ์ดํ›„๋ถ€ํ„ฐ ์šฐ๋ฆฌ๊ฐ€ ๋‹ค๋ฃจ๊ณ ์žํ•˜๋Š” UITransitionView ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋ผ์ดํ”„ ์‚ฌ์ดํด์—์„œ alpha ๊ฐ’์„ ์กฐ์ •ํ•˜๊ฒŒ ๋˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ถ€์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ UI ๊ฐ€ ๋ณ€ํ•  ์ˆ˜ ๋ฐ–์— ์—†์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿšจ ํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ…

์•„์ง ๋งŒ๋“ค์–ด์ง€์ง€ ์•Š์€ ๋ทฐ๊ฐ€ ์ด๋ ‡๊ฒŒ ๋ทฐ ๊ณ„์ธต์„ ๊ฐ€์งˆ ๊ฒƒ์ด๋‹ค ๋ผ๋Š” ์ „์ œ๋ฅผ ๊ฐ€์ง€๊ณ  ๋ทฐ์— ์ ‘๊ทผํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

๊ทธ ๊ฒฐ๊ณผ ํŠน์ • ๋ผ์ดํ”„ ์‚ฌ์ดํด ์ดํ›„์— ๋ทฐ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์—ˆ๊ณ , ๋ถ€์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ UI ๊ฐ€ ๊ทธ๋ ค์ง€๋Š” ๊ฒƒ์— ์ด๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค๊ณ  ํŒ๋‹จํ–ˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜ญ

๐Ÿ‘‰ ์ ‘๊ทผ

UITransitionView ๋ฅผ ๋ณด๋‹ˆ present() ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด์„œ ๋ทฐ๋ฅผ ๋ณด์—ฌ์ค„ ๋•Œ UISheetPresentationController ์„ค์ • ์—†์ด๋„ ์•„๋ž˜์™€ ๊ฐ™์ด ๋‹ค์Œ ํ™”๋ฉด์„ ๋„์–ด์ค„ ๋•Œ๋„ dimming view ๊ฐ€ ์žˆ๋˜ ๊ฒƒ์ด ์ƒ๊ฐ๋‚ฌ์Šต๋‹ˆ๋‹ค.

nextViewController.modalPresentationStyle = .pageSheet

์—ญ์‹œ๋‚˜ ๋™์ผํ•œ UIDimmingView ์˜€์Šต๋‹ˆ๋‹ค.

16

๋ฌธ์ œ์˜ ๊ด€์ ์„ ๋ฐ”๊พธ์–ด์„œ modalPresentationStyle.pageSheet ์ผ ๋•Œ dimming view ์˜ alpha ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด์•ผํ•˜๋Š” ๋ฌธ์ œ์ž„์„ ์•Œ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ด๋Š” ๋”์ด์ƒ UISheetPresentationController ์™€ ๊ด€๋ จ๋œ ๋ฌธ์ œ๊ฐ€ ์•„๋‹Œ UIPresentationController ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›์•„ presentationController ์„ ์ปค์Šคํ…€ํ•ด์•ผํ•˜๋Š” ๋ฌธ์ œ์ž„์„ ์•Œ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
๋งํฌ
Total
Today
Yesterday