June 7, 2021, TIL (Today I Learned)

Inwoo Hwang·2021년 8월 26일
0
post-thumbnail

학습내용


Responder?

이벤트를 핸들링하고 이벤트에 반응할 수 있는 객체. 모든 responder 객체는 UIResponder에서 상속된 클래스의 인스턴스. 모든 UIApplication, UIWindow, UIViewController, UIView의 객체들은 responder입니다.

Responder chain?

Responder 객체들이 이벤트나 액션 메시지를 핸들링할 책임을 앱의 다른 객체들에게 전송할 수 있도록 함. 또한 UIKit responder은 처리되지 않은 이벤트를 앱의 다른 파트로 forwarding 하는 일도 담당함.

존재하는 이유: 이벤트를 처리할 수 없는 상황이거나 힘든 상황에서 다른 이벤트를 handle할 주체는 누구일지 정해주는 연결고리 역할

iOS 환경에서 사용자의 터치 이벤트를 알아채거나 제어할 수 있는 방법의 종류

responder objects

  • When your app receives an event, UIKit automatically directs that event to the most appropriate responder object, known as the first responder.

앱이 이벤트를 수신하면 UIKit는 자동으로 해당 이벤트를 첫 번째 응답자로 알려진 가장 적절한 응답자 개체로 보냅니다.

  • func touchesBegan(Set<UITouch>, with: UIEvent?)
  • func touchesMoved(Set<UITouch>, with: UIEvent?)
  • func touchesEnded(Set<UITouch>, with: UIEvent?)
  • func touchesCancelled(Set<UITouch>, with: UIEvent?)
  • func touchesEstimatedPropertiesUpdated(Set<UITouch>

View 위에 Tap Gesture Recognizer가 존재할 때, 사용자가 뷰 영역을 터치하면 터치 이벤트를 가장먼저 수신하는 주체는 누구일까요?

UITapGestureRecognizer 오브젝트 UITapGestureRecognizer는 사용자의 tap을 감지하고 action method에게 먼저 보고합니다.

UITapGestureRecognizer

핸들링의 첫번째 UIView

@IBAction func tapPiece(_ gestureRecognizer : UITapGestureRecognizer ) {
   guard gestureRecognizer.view != nil else { return }
        
   if gestureRecognizer.state == .ended {      // Move the view down and to the right when tapped.
      let animator = UIViewPropertyAnimator(duration: 0.2, curve: .easeInOut, animations: {
         gestureRecognizer.view!.center.x += 100
         gestureRecognizer.view!.center.y += 100
      })
      animator.startAnimation()
   }}

Apple Developer Documentation

responder 객체들이 이벤트나 액션 메시지를 핸들링해야될것을 앱 내 타 객체에 전송하도록 도와줌.

responder가 해당 이벤트를 핸들링하지 않을때, chain의 타 객체로 포워딩한다.

이벤트는 처리될때까지 responder chains의 상위 객체로 이동 (끝까지 처리 안될 시 소멸)

  • 이벤트 경로

: responder chain은 기본적으로 이벤트라면 뷰(first responder) -> 뷰 계층 -> window 객체 -> App 객체

: View -> SuperView 포워딩 / rootView -> VC 포워딩

: UIKit가 규칙에 따라 responder chain을 동적 관리

iOS 환경에서 사용자가 일으킬 수 있는 이벤트의 종류는?

Determining an Event's First Responder

First Responder? 앱에서 이벤트들을 처음으로 받는 Responder객체. 앱이 이벤트를 받으면 UIKit은 First Responder에게 보낸다.

Determining an Event's First Responder

Standard Gestures

Gestures - User Interaction - iOS - Human Interface Guidelines - Apple Developer

What are the standard gestures in iOS?

< 공식문서 >

Using Responders and the Responder Chain to Handle Events

Touches, Presses, and Gestures

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

https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/handling_touches_in_your_view

gestureRecognizer자체가 화면에 손가락을 터치하면 uikit은 uitoouch object를 만들어서 responder가

When a touch occurs, UIKit creates a UITouch object and associates it with a view. As the touch location or other parameters change, UIKit updates the same UITouch object with the new information. The only property that does not change is the view. (Even when the touch location moves outside the original view, the value in the touch’s view property does not change.) When the touch ends, UIKit releases the UITouch object.

Ref.

[ios] Responder Chain and Touch Event

iOS의 Responder와 Responder Chain 이해하기

Responder Chain / Touch Event

iOS - Responder Chain이란

iOS - UIResponder, Responder Chain 알아보기

iOS ) UIResponder

profile
james, the enthusiastic developer

0개의 댓글