Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- collectionview
- Human interface guide
- 리펙토링
- swift documentation
- UITextView
- ios
- tableView
- 리팩토링
- 스위프트
- Observable
- Clean Code
- uitableview
- map
- swiftUI
- Refactoring
- SWIFT
- combine
- ribs
- rxswift
- Protocol
- UICollectionView
- 리펙터링
- 애니메이션
- clean architecture
- 클린 코드
- MVVM
- RxCocoa
- HIG
- uiscrollview
- Xcode
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] touches 제스쳐 (touchesBegin, touchesMoved, touchesEnded, touchesCancelled) 본문
iOS 응용 (swift)
[iOS - swift] touches 제스쳐 (touchesBegin, touchesMoved, touchesEnded, touchesCancelled)
jake-kim 2022. 3. 26. 21:07touches 제스쳐
- touches 제스쳐는 UIResponder에 기본적으로 구현되어 있는 메소드로 4가지가 존재
// UIResponder
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEstimatedPropertiesUpdated:(NSSet<UITouch *> *)touches API_AVAILABLE(ios(9.1));
- UIView와 UIViewController는 UIResponder를 상속받고 있으므로, 모든 UIView는 4가지 메소드를 사용 가능
touches 제스쳐 4가지
- touchesBegan: 화면을 클릭하기 시작할 때 실행
- touchesMoved: 화면에 드래그 했을 때 실행
- touchesEnded: 화면을 클릭 후 뗄 때 실행
- touchesCancelled: 위 3가지 이벤트가 발생도중에 system alert와 같은게 발생한 경우, touchesCanclled 발생
예제 전체 코드)
import UIKit
class ViewController: UIViewController {
private lazy var toucheLabel: UILabel = {
let label = UILabel()
label.text = "label"
label.font = .systemFont(ofSize: 24)
label.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(label)
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(self.toucheLabel)
NSLayoutConstraint.activate([
self.toucheLabel.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
self.toucheLabel.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
])
}
var beganCount = 0
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
self.beganCount += 1
self.toucheLabel.text = "touchesBegan \(self.beganCount)"
}
var movedCount = 0
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
self.movedCount += 1
self.toucheLabel.text = "touchesMoved \(self.movedCount)"
}
var endedCount = 0
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
self.endedCount += 1
self.toucheLabel.text = "touchesEnded \(self.endedCount)"
}
var cancelledCount = 0
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
self.cancelledCount += 1
self.toucheLabel.text = "touchesCancelled \(self.cancelledCount)"
}
}
'iOS 응용 (swift)' 카테고리의 다른 글
Comments