๐ŸŽ ์•„์ด-์˜ค-์—์Šค/๐Ÿ“ฑ iOS ๊ฐœ๋ฐœ

[iOS] UIResponder: iOS์˜ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ - Responder Chain๊ณผ First Responder

๊ฐœ๋ฐœํ•˜๋Š” ํ›ˆ์ด 2021. 10. 3. 17:12

UITextField ์“ฐ๋ฉด์„œ ๋งŽ์ด ๋ณธ๊ฑฐ..

์ตœ๊ทผ๋ฐ UITextField๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ ์‚ฌ์šฉ์ž๊ฐ€ ํ‚ค๋ณด๋“œ์˜ ์—”ํ„ฐ(return)์„ ๋ˆŒ๋ €์„ ๋•Œ ํ˜„์žฌ ํ…์ŠคํŠธ ํ•„๋“œ ๋ฐ”๋กœ ๋‹ค์Œ์— ์žˆ๋Š” ํ…์ŠคํŠธ ํ•„๋“œ๋กœ editing์ด ์ „ํ™˜๋˜๋„๋ก ๋งŒ๋“ค์–ด์•ผ ํ•˜๋Š” ์ž‘์—…์„ ํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. iOS ์ดˆ๋ณด์ด๋‹ค๋ณด๋‹ˆ๊นŒ ์—”ํ„ฐ ๋ˆ„๋ฅด๋ฉด ๋‹น์—ฐํžˆ ์ž๋™์œผ๋กœ ๋„˜์–ด๊ฐ€๋Š”๊ฑด์ค„ ์•Œ์•˜๋Š”๋ฐ ๊ทธ๊ฒŒ ์•„๋‹ˆ๋”๋ผ๊ตฌ์š”.. ๊ตฌ๊ธ€๋ง ๋์— ๊ฐœ๋ฐœ์ž ๋ถ„๋“ค์ด ์ถ”์ฒœํ•ด์ฃผ์‹œ๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ด๋ดค์Šต๋‹ˆ๋‹ค. 

 



์ด๋ ‡๊ฒŒ ๋ทฐ UITextFieldDelegate๋ฅผ ์ฑ„ํƒํ•˜๊ณ , textFieldShouldReturn ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•ด์„œ ์—”ํ„ฐ๊ฐ€ ๋ˆŒ๋ ธ์„ ๋•Œ ๋‹ค์Œ์— ์„ ํƒ๋  UITextField๋ฅผ FirstResponder๋กœ ์ง€์ •ํ•ด์ฃผ๋Š”๊ฑด๋ฐ์š”, ์ด๋ ‡๊ฒŒ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์‹คํ–‰ํ•ด๋ณด๋ฉด

 

 

์ž˜ ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿผ FirstResponder๊ฐ€ ๋ญ˜๊นŒ์š”?? ์ด ํฌ์ŠคํŠธ๋Š” First Responder์˜ ์ •์ฒด์™€ UIResponder์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด๋Š” ํฌ์ŠคํŠธ์ž…๋‹ˆ๋‹ค!!

 

UIResponder -  ๊ณต์‹๋ฌธ์„œ ์ฝ์–ด๋ณด๊ธฐ

First Responder ๊ฐ€ ๋œ๋‹ค๋Š” ๊ฒƒ์€ ๊ฐ€์žฅ ์ฒ˜์Œ Responder๊ฐ€ ๋œ๋‹ค๋Š” ์˜๋ฏธ์ด๊ฒ ์ฃ ..! ๊ทธ๋ž˜์„œ Responder๊ฐ€ ๋ฌด์—‡์ธ์ง€๋ถ€ํ„ฐ ์•Œ์•„๋ณด๋ ค๊ณ ํ•ฉ๋‹ˆ๋‹ค. UIResponder์˜ ๊ณต์‹๋ฌธ์„œ๋ฅผ ๋ด…์‹œ๋‹ค!

 

https://developer.apple.com/documentation/uikit/uiresponder

 

Apple Developer Documentation

 

developer.apple.com

 

๐Ÿ’กResponder objects—that is, instances of  UIResponder —constitute the event-handling backbone of a UIKit app. Many key objects are also responders, including the UIApplication object, UIViewController objects, and all UIView objects (which includes UIWindow). As events occur, UIKit dispatches them to your app's responder objects for handling.

 

Responder ๊ฐ์ฒด๋Š” UIResponder์˜ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด ์ธ์Šคํ„ด์Šค๊ฐ€ UIKit์—์„œ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ์˜ ์ค‘์ถ”์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. UIKit์˜ ๋งŽ์€ ๊ฐ์ฒด๋“ค, UIApplication, UIViewController, UIView๊ฐ™์€ ๊ฐ์ฒด๋“ค์ด ๋ชจ๋‘ Responder ์ด๊ธฐ๋„ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด UIKit ์€ ์ด๋ฒคํŠธ๋ฅผ Responder ๊ฐ์ฒด์—๊ฒŒ ์ „๋‹ฌํ•ด์„œ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

 

๐Ÿ’กThere are several kinds of events, including touch events, motion events, remote-control events, and press events. To handle a specific type of event, a responder must override the corresponding methods. For example, to handle touch events, a responder implements the touchesBegan(_:with:), touchesMoved(_:with:), touchesEnded(_:with:), and touchesCancelled(_:with:) methods. In the case of touches, the responder uses the event information provided by UIKit to track changes to those touches and to update the app's interface appropriately.

 

ํ™”๋ฉด์„ ํ„ฐ์น˜ํ•˜๊ฑฐ๋‚˜, ์ œ์Šค์ณ๋ฅผ ์ทจํ•˜๋Š” ๋“ฑ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ด๋ฒคํŠธ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์–ด๋–ค ํŠน์ •ํ•œ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋ ค๋ฉด ๋ฐ˜๋“œ์‹œ ํ•ด๋‹น ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ๋ฉ”์„œ๋“œ๋ฅผ responder ๊ฐ์ฒด๊ฐ€ ์˜ค๋ฒ„๋ผ์ด๋“œ ํ•ด์„œ ๋‚ด์šฉ์„ ๊ตฌํ˜„ํ•ด์•ผํ•œ๋‹ค๊ณ  ํ•˜๋„ค์š”. touchesBegan, touchesMoved ๊ฐ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์™€ UIView์™€ ์„ธ๋ถ€ ๋ทฐ์—์„œ ์ •์˜ํ•  ์ˆ˜ ์žˆ์—ˆ๋˜ ๊ฒƒ๋„ ๋ชจ๋‘ ์ด ๊ฐ์ฒด๋“ค์ด Responder ์ด๊ธฐ ๋•Œ๋ฌธ์ด๊ฒ ๋„ค์š”! ์˜ˆ๋ฅผ ๋“ค์–ด์„œ, ํ„ฐ์น˜ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด responder ๊ฐ์ฒด๋Š” UIKit์—์„œ ์ œ๊ณตํ•˜๋Š” ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์•ฑ์˜ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

๐Ÿ’กIn addition to handling events, UIKit responders also manage the forwarding of unhandled events to other parts of your app. If a given responder does not handle an event, it forwards that event to the next event in the responder chain. UIKit manages the responder chain dynamically, using predefined rules to determine which object should be next to receive an event. For example, a view forwards events to its superview, and the root view of a hierarchy forwards events to its view controller.

 

์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, UIKit์˜ responder ๋“ค์€ ์ž์‹ ์ด ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š๋Š” ์ด๋ฒคํŠธ๋ฅผ ์•ฑ์˜ ๋‹ค๋ฅธ ์š”์†Œ๋“ค์—๊ฒŒ ์ „๋‹ฌํ•˜๋Š” ์—ญํ• ๋„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ์— ์–ด๋–ค responder ๊ฐ์ฒด๊ฐ€ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์œผ๋ฉด, ์ด ๊ฐ์ฒด๊ฐ€ Responder Chain์˜ ๋‹ค์Œ responder์—๊ฒŒ ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ค๋‹ฌํ•ฉ๋‹ˆ๋‹ค. Responder Chain์€ UIKit์— ์˜ํ•ด ๋ฏธ๋ฆฌ ์ •ํ•ด์ง„ ๊ทœ์น™์— ๋”ฐ๋ผ ๋™์ ์œผ๋กœ ๊ด€๋ฆฌ๋ฉ๋‹ˆ๋‹ค. ์ด ๊ทœ์น™์€ ์–ด๋–ค ๊ฐ์ฒด์˜ ๋‹ค์Œ reponder๊ฐ€ ๋ˆ„๊ฐ€ ๋  ๊ฒƒ์ธ์ง€์— ๋Œ€ํ•œ ๊ทœ์น™์ธ ๊ฒƒ ๊ฐ™๋„ค์š”. ์˜ˆ์‹œ๋ฅผ ๋ณด๋‹ˆ ๋” ๋ช…ํ™•ํ•ด์ง€๋Š”๋ฐ์š”, View ๋Š” ์ž์‹ ์˜ Super View์—๊ฒŒ ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•˜๊ณ  ๊ฐ€์žฅ ์ตœ์ƒ์œ„์— ์žˆ๋Š” View๋Š” View Controller ์—๊ฒŒ ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

 

์ƒˆ๋กœ์šด ์šฉ์–ด๊ฐ€ ๋‚˜์™”๋„ค์š”! Responder Chain! First Responder๋ž‘ ๋ญ”๊ฐ€ ์—„์ฒญ ์—ฐ๊ด€์ด ์žˆ์„ ๊ฒƒ ๊ฐ™์ง€ ์•Š๋‚˜์š”??

์ผ๋‹จ ๋‚จ์€ ๋ถ€๋ถ„์„ ๋‹ค ์ฝ์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

 

๐Ÿ’กResponders process UIEvent objects but can also accept custom input through an input view. The system's keyboard is the most obvious example of an input view. When the user taps a UITextField and UITextView object onscreen, the view becomes the first responder and displays its input view, which is the system keyboard. Similarly, you can create custom input views and display them when other responders become active. To associate a custom input view with a responder, assign that view to the inputView property of the responder.

 

Responder ๊ฐ์ฒด๋“ค์€ UIEvent ๊ฐ์ฒด๋“ค์„ ์ฒ˜๋ฆฌํ•˜์ง€๋งŒ input view๋ฅผ ํ†ตํ•ด์„œ ์ปค์Šคํ…€ ์ž…๋ ฅ์„ ๋ฐ›์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ปค์Šคํ…€ ์ž…๋ ฅ์˜ ๊ฐ€์žฅ ๋ช…ํ™•ํ•œ ์˜ˆ๊ฐ€ ํ‚ค๋ณด๋“œ์ผํ…๋ฐ์š”, ์‚ฌ์šฉ์ž๊ฐ€ ํ™”๋ฉด์— ์žˆ๋Š” UITextField์™€ UITextView๋ฅผ ํƒญํ•˜๋ฉด, ํ•ด๋‹น ๋ทฐ๋Š” First Responder๊ฐ€ ๋˜์–ด์„œ ์ž…๋ ฅ ๋ทฐ, ์ฆ‰ ํ‚ค๋ณด๋“œ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค. ์ด์ฒ˜๋Ÿผ ๊ฐœ๋ฐœ์ž๋Š” ์ปค์Šคํ…€ ์ž…๋ ฅ ๋ทฐ๋ฅผ ๋งŒ๋“ค์–ด์„œ ์–ด๋–ค reponder ๊ฐ์ฒด๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด ํ™”๋ฉด์— ํ‘œ์‹œ๋˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ปค์Šคํ…€ ์ž…๋ ฅ ๋ทฐ๋ฅผ responder ๊ฐ์ฒด์˜ inputView ํ”„๋กœํผํ‹ฐ์— ๋„ฃ์–ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค!

 

๋ฌธ์„œ์˜ Overview ๋ถ€๋ถ„์„ ์ด๋ ‡๊ฒŒ ๋‹ค ์ฝ์–ด๋ดค๋Š”๋ฐ์š”, ์ค‘์š”ํ•œ ๋‚ด์šฉ๋“ค์„ ์ •๋ฆฌํ•ด๋ณด๋ฉด ์ด๋ ‡์Šต๋‹ˆ๋‹ค.

  1. UIView, ViewController ๋“ฑ ๋งŽ์€ UIkit์˜ ๊ฐ์ฒด๋“ค์€ UIResponder ์ธ์Šคํ„ด์Šค์ด๋‹ค. ๐Ÿ‘‰ Responder
  2. UIKit์€ UIResponder ๊ฐ์ฒด๋“ค์„ ์—ฐ๊ฒฐํ•ด์„œ ๊ด€๋ฆฌํ•œ๋‹ค. ๐Ÿ‘‰ Responder Chain
  3. UIkit์€ ์•ฑ์—์„œ ํ™”๋ฉด ํ„ฐ์น˜์™€ ๊ฐ™์€ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด Responder์—๊ฒŒ ์ด๋ฒคํŠธ๋ฅผ ๋ณด๋‚ธ๋‹ค.
  4. ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์€ Responder๋“ค์€ ์ž์‹ ์ด ์ฒ˜๋ฆฌํ•˜๊ฑฐ๋‚˜ Responder Chain์— ์žˆ๋Š” ์ž์‹ ์˜ ๋‹ค์Œ Responder์—๊ฒŒ ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•œ๋‹ค 
  5. First Responder๋กœ ์ง€์ •๋œ Responder๋Š” ์ด๋ฒคํŠธ๋ฅผ ๊ฐ€์žฅ ๋จผ์ € ์ „๋‹ฌ๋ฐ›๋Š” Responder์ด๋‹ค. ๐Ÿ‘‰ First Responder

becomeFirstResponder()๋ฅผ ์™œ ์ผ๋Š”์ง€ ์ด์ œ ์•Œ๊ฒ ๋‹ค!

์ด์ œ ํ‚ค๋ณด๋“œ์—์„œ ์—”ํ„ฐ๋ฅผ ๋ˆŒ๋ €์„ ๋•Œ ๋‹ค์Œ ํ…์ŠคํŠธ ํ•„๋“œ๋กœ ์ด๋™ํ•˜๊ธฐ์œ„ํ•ด becomeFirstResponder๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์ด์œ ๊ฐ€ ์™€๋‹ฟ์œผ์‹œ๋‚˜์š”? 

 

์—”ํ„ฐ๋ฅผ ๋ˆŒ๋ €์„ ๋•Œ, ํฌ์ปค์Šค ๋˜์–ด์žˆ๋Š” ํ…์ŠคํŠธํ•„๋“œ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ์›ํ•˜๋Š” ํ…์ŠคํŠธ ํ•„๋“œ๋ฅผ ํ‚ค๋ณด๋“œ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ First Responder๋กœ ํ…์ŠคํŠธ๋ฅผ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค! ํ™”๋ฉด์ด ํƒญ ๋˜๊ณ  ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด, ์ด ์ด๋ฒคํŠธ๊ฐ€ first responder๋กœ ์ง€์ •๋œ UITextView์— ์ „๋‹ฌ๋˜๋ฉด์„œ ํ•„๋“œ์— ๊ธ€์ž๊ฐ€ ์ฑ„์›Œ์กŒ๋˜ ๊ฒƒ์ด์ฃ !

์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ ๊ณผ์ • 

 

 

Apple Developer Documentation

 

developer.apple.com

 

 

๊ทธ๋Ÿผ ์ด์ œ UIKit์ด Responder์™€ Responder Chain์„ ํ†ตํ•ด ์–ด๋–ป๊ฒŒ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š”์ง€ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! ์œ„ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด UILabel, UITextField, UIButton์ด ํฌํ•จ๋œ ์•ฑ์ด ์žˆ๋‹ค๊ณ  ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ UITextField๊ฐ€ ์–ด๋–ค ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์•˜์„ ๋•Œ UITextField๊ฐ€ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ•œ๋‹ค๋ฉด, UIKit์€ ์ด ์ด๋ฒคํŠธ๋ฅผ UITextField์˜ ์ƒ์œ„ ๋ทฐ์ธ UIView ๋กœ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์—ฌ๊ธฐ์„œ ์ด๋ฒคํŠธ๊ฐ€ ์ฒ˜๋ฆฌ๋˜์ง€ ๋ชปํ•˜๋ฉด ๊ทธ ์ƒ์œ„ ๋ทฐ์ธ UIView์— ์ „๋‹ฌ๋˜๊ณ , ์ด ๋ทฐ์™€ ์—ฐ๊ฒฐ๋œ UIViewController๋ฅผ ๊ฑฐ์ณ UIWindow๊นŒ์ง€ ์—ฐ์‡„์ ์œผ๋กœ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋„ ์ด๋ฒคํŠธ๊ฐ€ ์ฒ˜๋ฆฌ๋˜์ง€ ๋ชปํ•˜๋ฉด UIApplication๊นŒ์ง€ ์˜ฌ๋ผ๊ฐ€์„œ ์ฒ˜๋ฆฌ๋  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

 

UIkit์ด first responder๊ฐ€ ์–ด๋–ค ๊ฐ์ฒด๊ฐ€ ๋ ์ง€ ํŒ๋‹จํ•˜๋Š” ๊ธฐ์ค€์€ ๋ฐœ์ƒํ•œ ์ด๋ฒคํŠธ์— ๋”ฐ๋ผ์„œ ๋‹ฌ๋ผ์ง‘๋‹ˆ๋‹ค!

 

๊ทธ๋Ÿผ ๋งŒ์•ฝ ํ„ฐ์น˜ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ, ์–ด๋–ค Responder์—์„œ ๋ฐœ์ƒํ•œ ์ด๋ฒคํŠธ์ธ์ง€ UIKit์ด ์–ด๋–ป๊ฒŒ ์•Œ๊นŒ์š”? UIKit์€ hitTest๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐ€์žฅ ์ƒ์œ„์— ๋†“์ธ ๋ทฐ๋ฅผ ์ฐพ๊ณ  ํ•ด๋‹น ๋ทฐ๋ฅผ first responder๋กœ ์ง€์ •ํ•ด ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. ํ„ฐ์น˜๊ฐ€ ์‹œ์ž‘๋˜๋ฉด UIKit์€ UITouch ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ„ฐ์น˜์˜ ์ขŒํ‘œ์™€ ๊ฐ™์€ ์ •๋ณด๋“ค์„ ์ €์žฅํ•˜๊ณ  ๊ฐฑ์‹ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ„ฐ์น˜๊ฐ€ ์ข…๋ฃŒ๋˜๋ฉด ์ƒ์„ฑํ–ˆ๋˜ UITouch ์ธ์Šคํ„ด์Šค๋ฅผ ํ•ด์ œํ•ฉ๋‹ˆ๋‹ค.

 

๊ธฐ๋ณธ์ ์ธ Responder Chain

Responder ๊ฐ์ฒด๋“ค์€ ๋ชจ๋‘ next ํ”„๋กœํผํ‹ฐ๋ฅผ ๊ฐ€์ ธ์„œ ์ž์‹ ์˜ ๋‹ค์Œ responder๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ๋„๋ก ํ•˜๋Š”๋ฐ์š”, ์ด ํ”„๋กœํผํ‹ฐ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋“œํ•ด์„œ next responder๋ฅผ ๋ณ€๊ฒฝํ•ด์ค„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ •๋˜์–ด ์žˆ๋‹ค๊ณ  ํ•ด์š”!

 

- UIView: UIView์™€ ํ•˜์œ„ ํƒ€์ž…๋“ค์€ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์˜ ๋ฃจํŠธ ๋ทฐ์ผ ๊ฒฝ์šฐ์—๋งŒ next responder๋กœ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๊ฐ€์ง€๊ณ , ๋‚˜๋จธ์ง€ ๊ฒฝ์šฐ์—๋Š” ๋ชจ๋‘ ์ž์‹ ์„ ํฌํ•จํ•˜๋Š” ์ƒ์œ„ ๋ทฐ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

- UIViewController: ๋งŒ์•ฝ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์˜ ๋ฃจํŠธ ๋ทฐ๊ฐ€ window์˜ ๋ฃจํŠธ ๋ทฐ๋ผ๋ฉด, next responder๋Š” UIWindow ๊ฐ์ฒด๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์–ด๋–ค ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ๋‹ค๋ฅธ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์— ์˜ํ•ด present ๋˜์—ˆ๋‹ค๋ฉด, ์ด ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋Š” ์ž์‹ ์„ ํ˜ธ์ถœํ•œ ๋ทฐ๋ฅผ next responder๋กœ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

- UIWindow: UIWindow ๊ฐ์ฒด๋Š” UIApplication์„ next responder๋กœ ๊ฐ‘๋‹ˆ๋‹ค.

- UIApplication: UIApplication์€ AppDelegate ๊ฐ€ UIResponder์˜ ์ธ์Šคํ„ด์Šค์ด๊ณ , ๋ทฐ, ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ์— AppDelegate๋ฅผ next responder๋กœ ๊ฐ‘์ง‘๋‹ˆ๋‹ค.

 

์ด ์ˆœ์„œ๋Š” ์œ„์˜ ๊ทธ๋ฆผ๊ณผ ๋˜‘๊ฐ™์ฃ ? ๋‹ค์‹œ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ •๋ฆฌํ•˜๋ฉด,

 

iOS ์•ฑ์€ UIView -> UIViewController -> UIWindow -> UIApplication -> AppDelegate ์ˆœ์„œ๋กœ ์ด๋ฒคํŠธ๊ฐ€ ์ „๋‹ฌ๋˜๋ฉฐ, ์–ด๋–ค ๊ฐ์ฒด๊ฐ€ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ•˜๋ฉด ๋‹ค์Œ ๊ฐ์ฒด๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค!

 

UIResponder์™€ FirstResponder์— ๋Œ€ํ•ด ์ด์ œ ์ดํ•ด๊ฐ€ ๊ฐ€์‹œ๋‚˜์š”? ์—ฌ๊ธฐ์„œ ํฌ์ŠคํŠธ๋ฅผ ๋งˆ๋ฌด๋ฆฌํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค! ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :)