ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [iOS] ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ (Responder Chain) ์ด๋ž€? (feat. UIResponder, First Responder, UIEvent)
    iOS/๐Ÿค– App 2021. 7. 12. 13:25

     ์•ˆ๋…•ํ•˜์„ธ์š”๐Ÿถ

     

    ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ (Responder Chain) ์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

    ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์„ ๊ณต๋ถ€ํ•˜๋ฉด

    ์•ฑ ๋‚ด์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ์ „๋‹ฌ๋˜๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

     

    ์ด ๊ธ€์—์„œ ๋‹ค๋ฃจ๋Š” ๊ฒƒ:

    UIResponder, Responder Chain, First Responder, UIEvent

     

     

     

    ๊ทธ๋Ÿผ ์‹œ์ž‘ํ•ด๋ณผ๊ฒŒ์š”๐Ÿ”ฅ


     

    ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์€ ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ๋“ค์ด ๋™์ ์œผ๋กœ ๊ตฌ์„ฑ๋œ ์ด๋ฒคํŠธ ์ „๋‹ฌ ์ฒด์ธ ์ž…๋‹ˆ๋‹ค.

     

    ์•ฑ์€ ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

     

    ์—ฌ๊ธฐ์„œ ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ๋ž€ UIReponder ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€๋ฆฌํ‚ต๋‹ˆ๋‹ค.

     

    ๋Œ€ํ‘œ์ ์œผ๋กœ UIView (๊ทธ๋ฆฌ๊ณ  UIView์˜ ์„œ๋ธŒํด๋ž˜์Šค์ธ UIWindow) , UIViewController, UIApplication ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ๋ฆฌ์Šคํฐ๋”๋Š” Event Raw Data ๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ๋งŒ์•ฝ ๋ฆฌ์Šคํฐ๋”๊ฐ€ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์•˜๋‹ค๋ฉด ๋ฆฌ์Šคํฐ๋”๋Š” ๋ฐ˜๋“œ์‹œ ๊ทธ๊ฒƒ์„ ์ฒ˜๋ฆฌํ•˜๊ฑฐ๋‚˜, ๋‹ค๋ฅธ ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ๋กœ ๋„˜๊ฒจ์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

     

    ์•ฑ์ด ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌ๋ฐ›์•˜์„ ๋•Œ,

    UIKit ์€ ์ž๋™์œผ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ์— ๊ฐ€์žฅ ์ ์ ˆํ•œ ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

     

     

    ์—ฌ๊ธฐ์„œ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ์— ๊ฐ€์žฅ ์ ์ ˆํ•œ ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ๋ฅผ First Responder ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

    ์›๋ž˜๋Š” ์ด๋Ÿฐ ๋œป

     

    ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š์€ ์ด๋ฒคํŠธ๋“ค์€ ๋ฆฌ์Šคํฐ๋”์—์„œ ๋‹ค๋ฅธ ๋ฆฌ์Šคํฐ๋”๋กœ

    ์‹ค์‹œ๊ฐ„ ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ (Active responder chain) ์— ๋”ฐ๋ผ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

     

    ์ด ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์€ ์•ฑ์˜ ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ์— ๋”ฐ๋ผ ๋™์ ์œผ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.

     

    ์•„๋ž˜ ๊ทธ๋ฆผ์€ Label, Textfield, Button ๊ทธ๋ฆฌ๊ณ  ๋‘ ๊ฐœ์˜ ๋ฐฑ๊ทธ๋ผ์šด๋“œ View ๋กœ UI ๋ฅผ ๊ตฌ์„ฑํ•œ ์•ฑ์˜ ๋ฆฌ์Šคํฐ๋”๋“ค์„ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ๊ทธ๋ฆผ์˜ ํ™”์‚ดํ‘œ๋ฅผ ํ†ตํ•ด ์˜ค๋ธŒ์ ํŠธ๋“ค์€ ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์œผ๋กœ ๊ตฌ์„ฑ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

     

    ํ™”์‚ดํ‘œ ๋ฐฉํ–ฅ์œผ๋กœ ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š์€ ์ด๋ฒคํŠธ๋“ค์ด ์ „๋‹ฌ ๋ฉ๋‹ˆ๋‹ค.

     

     

     

     

    ๋งŒ์•ฝ Textfield ๊ฐ€ ์ „๋‹ฌ๋ฐ›์€ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”?

     

    UIKit ์€ TextField ์˜ ์ˆ˜ํผ๋ทฐ์ธ UIView ๋กœ ์šฐ์„  ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

     

    ๋งŒ์•ฝ ์ด UIView ๋„ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, UIWindow ์˜ ๋ฃจํŠธ ๋ทฐ์ธ (๋‘ ๋ฒˆ์งธ ์ฒญ๋ก์ƒ‰) UIView ๋กœ ์ „๋‹ฌ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

     

    ๋ฃจํŠธ ๋ทฐ์—์„œ, ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์€ ๋ฃจํŠธ ๋ทฐ๋ฅผ ์†Œ์œ ํ•œ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

     

    ์œˆ๋„์šฐ๋กœ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ์€ ๊ทธ ์ดํ›„ ์ž…๋‹ˆ๋‹ค.

     

     

    >> ์œˆ๋„์šฐ์— ๋Œ€ํ•ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด?? <<

     

     

    ๋งŒ์•ฝ ์œˆ๋„์šฐ๊ฐ€ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ• ์ˆ˜ ์—†๋‹ค๋ฉด, UIKit ์€ ์ด๋ฒคํŠธ๋ฅผ UIApplication ์˜ค๋ธŒ์ ํŠธ๋กœ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

     

    ์ดํ›„ ์•ฑ ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ์— ์ „๋‹ฌ๋  ๊ฐ€๋Šฅ์„ฑ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.


     

    Determining an Event's First Responder

    " ์ด๋ฒคํŠธ์˜ First Responder ๊ฒฐ์ •ํ•˜๊ธฐ "

     

    ์œ„์—์„œ UIKit ์€ ์ด๋ฒคํŠธ๋ฅผ ๊ฐ€์žฅ ์ ์ ˆํ•œ ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ์— ์ „๋‹ฌํ•œ๋‹ค๊ณ  ์–ธ๊ธ‰ํ–ˆ๋Š”๋ฐ์š”.

     

    ๊ทธ๋ฆฌ๊ณ  ์ด ์˜ค๋ธŒ์ ํŠธ๋ฅผ 'First Responder' ๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค๊ณ ๋„ ๋งํ–ˆ์Šต๋‹ˆ๋‹ค.

     

    ๊ทธ๋ ‡๋‹ค๋ฉด UIKit ์€ ์–ด๋–ค ๊ธฐ์ค€์œผ๋กœ ์ด First Responder ๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๊ฒƒ์ผ๊นŒ์š”???

     

    ๋ฐ”๋กœ ๋ฐœ์ƒํ•œ ์ด๋ฒคํŠธ์˜ ํƒ€์ž…์ž…๋‹ˆ๋‹น

     

    ์—ฌ๊ธฐ์„œ ๋งํ•˜๋Š” ์ด๋ฒคํŠธ๋Š” UIEvent ์˜ ์ธ์Šคํ„ด์Šค์ธ๋ฐ, type ์— ๋”ฐ๋ผ ์—ฌ๋Ÿฌ ์ข…๋ฅ˜์˜ ์ด๋ฒคํŠธ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

     

     

    ์—ฌ๊ธฐ์„œ ๊ฐ€์žฅ ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ์ด๋ฒคํŠธ๋Š” ๋ฐ”๋กœ๋ฐ”๋กœ ํ„ฐ์น˜ ์ด๋ฒคํŠธ์ด๊ฒ ์ฃ ?

     

    ์ฐธ๊ณ ๋กœ

    Press ๋Š” ๋ฌผ๋ฆฌ ํ‚ค์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ด๋ฒคํŠธ

    Remote-control ์€ ํ—ค๋“œํฐ ๋“ฑ์˜ ์™ธ๋ถ€ ๊ธฐ๊ธฐ์—์„œ ๋ˆ„๋ฅด๋Š” ๋ฒ„ํŠผ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ด๋ฒคํŠธ,

    Editing menu ์˜ ๊ฒฝ์šฐ ์šฐ๋ฆฌ๊ฐ€ ์•„์ดํฐ์—์„œ Text ๋ฅผ ์งง๊ฒŒ ํ˜น์€ ๊ธธ๊ฒŒ ๋ˆ„๋ฅผ ๋•Œ ๋œจ๋Š” ๊ทธ ๋ฉ”๋‰ด์ž…๋‹ˆ๋‹ค.

     

    Editing Menu

     

    Shake-motion ์ด๋ฒคํŠธ๋Š” ํ”๋“ค ๋•Œ ๋ฐœ์ƒํ•˜๋Š”๋ฐ,

    ์ด๊ฒƒ์€ ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์—์„œ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š๊ณ  Core Motion ์˜ค๋ธŒ์ ํŠธ๋กœ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.

     


     

    ์ปจํŠธ๋กค์€ UIControl ์„ ์„œ๋ธŒํด๋ž˜์‹ฑํ•œ ํด๋ž˜์Šค์˜ ์˜ค๋ธŒ์ ํŠธ๋“ค์„ ๊ฐ€๋ฆฌํ‚ต๋‹ˆ๋‹ค.

     

    ์ปจํŠธ๋กค์€ target-action mechanism ์œผ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์ฃ .

     

    ๊ทธ๋ž˜์„œ ์ปจํŠธ๋กค์€ ์•ก์…˜ ๋ฉ”์‹œ์ง€๋ฅผ ์ด์šฉํ•ด ๋ฐ”๋กœ ์ž์‹ ์˜ ํƒ€์ผ“ ์˜ค๋ธŒ์ ํŠธ์™€ ์†Œํ†ตํ•ฉ๋‹ˆ๋‹ค.

     

    ์•ก์…˜ ๋ฉ”์‹œ์ง€๋Š” ์ด๋ฒคํŠธ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.

    ํ•˜์ง€๋งŒ ์—ฌ์ „ํžˆ ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์„ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.

     

    ์ปจํŠธ๋กค์˜ ํƒ€๊ฒŸ ์˜ค๋ธŒ์ ํŠธ๊ฐ€ ์„ค์ •๋˜์–ด ์žˆ์ง€ ์•Š์„ ๊ฒฝ์šฐ,

    UIKit์€ ํƒ€๊ฒŸ ์˜ค๋ธŒ์ ํŠธ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ

    ์•ก์…˜ ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ฐพ์„ ๋•Œ๊นŒ์ง€ ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์„ ๋Œ์•„๋‹ค๋‹™๋‹ˆ๋‹ค.

     

    ์˜ˆ๋ฅผ ๋“ค์–ด UIkit ์˜ editing menu ๋Š” ์œ„์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ž‘๋™ํ•˜๋Š”๋ฐ,

    cut(_ :), copy(_ : ), paste(_ :) ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ฐพ์œผ๋Ÿฌ ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์„ ๋Œ์•„๋‹ค๋‹ˆ๋Š” ๊ฒ๋‹ˆ๋‹ค.

     

    Editing Menu

     

    ๋ทฐ ์•ž์— Gestsure recognizer ๊ฐ€ ์žˆ๋‹ค๋ฉด, Gesture recognizer ๊ฐ€ ๋จผ์ € ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌ๋ฐ›๊ณ  ์ฒ˜๋ฆฌ๋ฅผ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.

     

    ๋งŒ์•ฝ ์‹คํŒจํ•œ๋‹ค๋ฉด, ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์— ๋”ฐ๋ผ ์ด๋ฒคํŠธ๊ฐ€ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.


     

    Determining Which Responder Contained a Touch Event

    " ์–ด๋–ค ๋ฆฌ์Šคํฐ๋”๊ฐ€ ์ด๋ฒคํŠธ๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š”์ง€ ๊ฒฐ์ •ํ•˜๊ธฐ "

     

     

    UIkit ์€ ๋ทฐ ๊ธฐ๋ฐ˜ hit-testing ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ„ฐ์น˜ ์ด๋ฒคํŠธ๊ฐ€ ์–ด๋””์„œ ๋ฐœ์ƒํ•˜์˜€๋Š”์ง€ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

     

    ๋” ๊ตฌ์ฒด์ ์œผ๋กœ ๋งํ•˜์ž๋ฉด, UIKit ์€ ํ„ฐ์น˜ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•œ ์œ„์น˜์™€ ๋ทฐ ๊ณ„์ธต์˜ ๋ทฐ ์˜ค๋ธŒ์ ํŠธ์˜ bounds ์™€ ๋น„๊ต๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

     

    UIView ์˜ hitTest(_:with:) ๋ฉ”์„œ๋“œ๋Š” ๋ทฐ ๊ณ„์ธต์„ ๋Œ์•„๋‹ค๋‹ˆ๋ฉฐ

    ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•œ ํ„ฐ์น˜ ์ง€์ ์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ๋ทฐ์˜ ๊ณ„์ธต ์ƒ ๊ฐ€์žฅ ์ตœํ•˜๋‹จ ์„œ๋ธŒ๋ทฐ๋ฅผ ์ฐพ๊ณ ,

    ๊ทธ๊ฒƒ์„ ํ„ฐ์น˜ ์ด๋ฒคํŠธ์˜ First Responder ๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

     

    ๋งŒ์•ฝ ํ„ฐ์น˜ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•œ ์œ„์น˜๊ฐ€ ๋ทฐ์˜ bounds ์˜ ๋ฐ–์— ์žˆ๋‹ค๋ฉด,

    hitTest(_:with:) ๋Š” ํ•ด๋‹น ๋ทฐ์™€ ์„œ๋ธŒ๋ทฐ๋ฅผ ๋ชจ๋‘ ๋ฌด์‹œํ•ฉ๋‹ˆ๋‹ค.

     

    ๊ฒฐ๊ณผ์ ์œผ๋กœ ๋ทฐ์˜ ์†์„ฑ clipsToBounds ๊ฐ€ false ๋กœ ์„ค์ •๋˜์–ด ์žˆ์„ ๋•Œ,

    ๋ทฐ์˜ bounds ๋ฅผ ๋ฒ—์–ด๋‚œ ์„œ๋ธŒ๋ทฐ์—์„œ ํ„ฐ์น˜๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋”๋ผ๋„ hitTest(_:with:) ๋Š” ๋ทฐ๋ฅผ ๋ฆฌํ„ดํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

     

    ์ด hit-testing ๋™์ž‘์— ๋Œ€ํ•ด์„œ ์ข€ ๋” ์ž์„ธํžˆ ์‚ดํŽด๋ณด์ž๋ฉด, hitTest(_:with:) ๋ฉ”์„œ๋“œ๋ฅผ ์‚ดํŽด๋ณด์•„์•ผํ•˜๋Š”๋ฐ์š”.

     

     

    hitTest(_:with:)

     

    ์šฐ์„  ์ด ๋ฉ”์„œ๋“œ๋Š” UIView ์˜ ์ธ์Šคํ„ด์Šค ๋ฉ”์„œ๋“œ์ด๊ตฌ์š”...

     

    ๋ฐœ์ƒํ•œ ์ด๋ฒคํŠธ๊ฐ€ ์ด ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

     

    ์ด ๋•Œ ์ด๋ฒคํŠธ๋Š” UIEvent ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

     

    ์ด ๋ฉ”์„œ๋“œ๋Š” ์ „๋‹ฌ๋ฐ›์€ ํฌ์ธํŠธ์— ์œ„์น˜ํ•œ ๋ทฐ ์ค‘ ์ž์‹ ์„ ํฌํ•จํ•˜์—ฌ ๋ทฐ ๊ณ„์ธต ์ตœํ•˜๋‹จ์˜ ์„œ๋ธŒ๋ทฐ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

     

    ๋งŒ์•ฝ ํ˜ธ์ถœ๋œ ๋ทฐ ๊ณ„์ธต์˜ ๋ฐ”๊นฅ์—์„œ ๋ฐœ์ƒํ•œ ์ด๋ฒคํŠธ์ผ ๊ฒฝ์šฐ nil ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

     

    ์ค‘์š”ํ•œ ์ ์€ ํ˜ธ์ถœ๋œ ๋ทฐ์˜ bounds ์˜ ๋ฐ”๊นฅ์—์„œ ๋ฐœ์ƒํ•œ ์ด๋ฒคํŠธ๋ผ๋ฉด nil ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

     

    ์ถ”๊ฐ€์ ์œผ๋กœ hidden์ด๊ฑฐ๋‚˜ alpha ๊ฐ’์ด 0.01 ์ดํ•˜๊ฑฐ๋‚˜

    user interation์„ disabled ํ•ด๋†“์€ ๋ทฐ๋ผ๋ฉด ๋ฌด์‹œ๋ฉ๋‹ˆ๋‹ค.

     

    ์ด ๋ฉ”์„œ๋“œ๋Š” hit์„ ๊ฒฐ์ •ํ•  ๋•Œ ๋ทฐ์˜ ์ปจํ…์ธ ๋ฅผ ๊ณ ๋ คํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

     

    ์ฆ‰, ์ฝ˜ํ…์ธ ์˜ ํˆฌ๋ช…ํ•œ ๋ถ€๋ถ„์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์–ด๋„ ๋ทฐ๋Š” ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค.

     

    ํ„ฐ์น˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด UIKit ์€ UITouch ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํ„ฐ์น˜๊ฐ€ ๋ฐœ์ƒํ•œ ๋ทฐ์™€ ๊ด€๋ จ์‹œ์ผœ์„œ ์ƒ์„ฑ์„ ํ•ฉ๋‹ˆ๋‹ค.

     

    ํ„ฐ์น˜์˜ ์œ„์น˜๋‚˜, ๋‹ค๋ฅธ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด UIKit ์€ ๋™์ผํ•œ UITouch ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒˆ๋กœ์šด ์ •๋ณด๋กœ ์—…๋ฐ์ดํŠธ ํ•ฉ๋‹ˆ๋‹ค.

     

    ์ด UITouch ์˜ค๋ธŒ์ ํŠธ์—์„œ ํ•ญ์ƒ ๋ณ€ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์žˆ๋Š”๋ฐ, ๋ฐ”๋กœ view ์†์„ฑ ์ž…๋‹ˆ๋‹ค.

     

    ์ด ์†์„ฑ์€ ๋งŒ์•ฝ ํ„ฐ์น˜์˜ ์œ„์น˜๊ฐ€ ๋‹ค๋ฅธ ๋ทฐ๋กœ ๋ฐ”๋€Œ์—ˆ์–ด๋„ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

    ( ์ฆ‰, ์†๊ฐ€๋ฝ์ด A ๋ทฐ์—์„œ B ๋ทฐ ์œ„๋กœ ์ด๋™ํ•˜์˜€์–ด๋„ view ์†์„ฑ์€ ๋ฐ”๋€Œ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.)


     

    Altering the Responder Chain

    "๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์„ ๋ณ€๊ฒฝํ•˜๊ธฐ"

     

     

    ์šฐ๋ฆฌ๋Š” ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ์˜ next ๋ผ๋Š” ์†์„ฑ์„ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•ด์„œ ๋ฆฌ์Šคํฐ๋” ์ฒด์ธ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ๋ณ€๊ฒฝ์„ ํ•œ๋‹ค๋ฉด, ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ๊ฐ€ ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•  ๋‹ค์Œ ๋ฆฌ์Šคํฐ๋”๋Š” ์šฐ๋ฆฌ๊ฐ€ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•œ ์˜ค๋ธŒ์ ํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

     

    ๋งŽ์€ UIKit ํด๋ž˜์Šค๊ฐ€ ์ด๋ฏธ ์ด next ์†์„ฑ์„ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ํ•˜์—ฌ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ๐ŸŸข ์˜ˆ๋ฅผ ๋“ค๋ฉด:

    UIView ์˜ค๋ธŒ์ ํŠธ๋Š” ๋งŒ์•ฝ ์ž์‹ ์ด ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์˜ ๋ฃจํŠธ ๋ทฐ๋ผ๋ฉด, ๋‹ค์Œ ๋ฆฌ์Šคํฐ๋” ์˜ค๋ธŒ์ ํŠธ๋Š” ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

     

    ๋ฃจํŠธ๋ทฐ๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด, ๋ทฐ์˜ ์ˆ˜ํผ๋ทฐ๊ฐ€ ๋‹ค์Œ ๋ฆฌ์Šคํฐ๋”๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

     

    UIViewController ์˜ค๋ธŒ์ ํŠธ๋Š” ๋งŒ์•ฝ ์ž์‹ ์ด ๊ด€๋ฆฌํ•˜๋Š” ๋ทฐ๊ฐ€ ์œˆ๋„์šฐ์˜ ๋ฃจํŠธ ๋ทฐ๋ผ๋ฉด, ๋‹ค์Œ ๋ฆฌ์Šคํฐ๋”๋Š” ์œˆ๋„์šฐ ์˜ค๋ธŒ์ ํŠธ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

     

    ๋˜ํ•œ ๋งŒ์•ฝ A ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ B ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์— ์˜ํ•ด present ๋˜๊ณ  ์žˆ๋‹ค๋ฉด

    ์šฐ๋ฆฌ๋Š” A ๋ฅผ Presented ViewController, B ๋ฅผ Presenting ViewController ๋ผ๊ณ  ๋ถ€๋ฅด์ฃ .

     

    ์ด ๋•Œ Presented ViewController์˜ ๋‹ค์Œ ๋ฆฌ์Šคํฐ๋”๋Š” presenting ViewController ์ž…๋‹ˆ๋‹ค.

     

    UIWindow ์˜ค๋ธŒ์ ํŠธ (์ฆ‰ ์œˆ๋„์šฐ) ์˜ ๋‹ค์Œ ๋ฆฌ์Šคํฐ๋”๋Š” UIApplication ์˜ค๋ธŒ์ ํŠธ ์ž…๋‹ˆ๋‹ค.

     

     

     

     

    ๋!


    ๐Ÿค–๐ŸŸข[์šฐ์งฑ์˜ iOS ๋ธ”๋กœ๊ทธ]๐Ÿ”ต๐Ÿ’ป

    iOS๋ฅผ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ๋ฐฐ์šด ๋‚ด์šฉ์„ ๊ธฐ๋กํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ์ฐธ๊ณ ์ž๋ฃŒ 1: https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/using_responders_and_the_responder_chain_to_handle_events

     

    ์ฐธ๊ณ ์ž๋ฃŒ 2: https://developer.apple.com/documentation/uikit/uiresponder

    'iOS > ๐Ÿค– App' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

    [iOS] Safe Area ์™€ Layout Margins ์ด๋ž€?  (3) 2021.08.10
    [iOS] Container View Controller ๋ž€?  (0) 2021.07.26
    [iOS] ์œˆ๋„์šฐ๋ž€? (feat. UIWindow)  (0) 2021.07.05
    [iOS] Core Animation ์ด๋ž€? (2)  (0) 2021.07.05
    [iOS] Core Animation ์ด๋ž€? (1)  (0) 2021.07.05

    ๋Œ“๊ธ€

์–ด์ œ๋ณด๋‹ค ๋ฐœ์ „ํ•œ ๋‚˜