## 1
아래의 영상은 화면을 특정 방향으로 잡아 끌었을 때 이벤트를 감지하여 어느 방향으로 잡아끌고 있는지 감지하여 화면에 표기해주는 기능을 구현한 것입니다.
구현 방법에는 크게 아래 두 가지 방법을 사용할 수 있습니다. 두 가지 방법 중 한 가지 방법을 골라 구현해보세요. (마우스 클릭 효과 동그라미는 구현하지 않습니다)
Gesture Recognizer
**UIView’s Touch Event Handling**
``` swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var label: UILabel!
var previousTouchedLocation: CGFloat = 0
override func viewDidLoad() {
super.viewDidLoad()
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if let currentTouch = touches.first {
let touchLocation = currentTouch.location(in: self.view)
print(touchLocation.x)
if touchLocation.x < previousTouchedLocation {
label.text = "왼쪽"
} else if touchLocation.x > previousTouchedLocation {
label.text = "오른쪽"
} else { return }
previousTouchedLocation = touchLocation.x
}
}
}
```
## 2
아래의 영상은 화면을 특정 방향으로 잡아 끌었을 때 이벤트를 감지하여 어느 방향으로 잡아끌고 있는지, 현재 사용자의 터치가 위치한 위치는 전체 뷰의 어디인지 감지하여 화면에 표기해주는 기능을 구현한 것입니다.
1에서 사용하지 않은 방식으로 구현해보세요.
**Gesture Recognizer**
```swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var panGestureRecognizer: UIPanGestureRecognizer!
@IBOutlet weak var recognizerLocationLabel: UILabel!
@IBOutlet weak var recognizerDirectionLabel: UILabel!
var previousLocation: CGFloat = 0
override func viewDidLoad() {
super.viewDidLoad()
recognizerDirectionLabel.text = "-"
recognizerLocationLabel.text = "-"
}
@IBAction func pullView(_ sender: UIPanGestureRecognizer) {
let location = panGestureRecognizer.location(in: self.view)
let x = Int(location.x)
let y = Int(location.y)
if location.x < previousLocation {
recognizerDirectionLabel.text = "왼쪽"
} else if location.x > previousLocation {
recognizerDirectionLabel.text = "오른쪽"
} else { return }
previousLocation = location.x
recognizerLocationLabel.text = "x: \(x), y: \(y)"
}
}
```
## 3 Questions
Q1 : Responder Chain이란 무엇입니까?
- 리스폰더 오브젝트들이 동적으로 구성된 이벤트 전달 체인
Q2 : Responder Chain과 Gesture Recognizer는 이벤트 제어에서 상호간 상관관계일까요? 별개관계일까요? 그렇게 생각한 이유는 무엇인가요?
Q3 : UIResponder 클래스의 역할은 무엇인가요? 클래스의 설명 An abstract interface for responding to and handling events.이 무엇을 뜻하는지 설명해주세요.