탭-터치 이벤트에 대응하는 카운트 예제 코드
아래와 같이 3개의 함수를 재정의 하면 됩니다. 탭과 터치의 차이는 연속해서 클릭(터치)하냐?의 차이입니다.
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
- override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
- override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)
전체소스는 아래와 같습니다.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var lblMessage: UILabel!
@IBOutlet weak var lblTapCount: UILabel!
@IBOutlet weak var lblTouchCount: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first! as UITouch
lblMessage.text = "Touch Began"
lblTapCount.text = String(touch.tapCount)
lblTouchCount.text = String(touches.count)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first! as UITouch
lblMessage.text = "Touch Moved"
lblTapCount.text = String(touch.tapCount)
lblTouchCount.text = String(touches.count)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first! as UITouch
lblMessage.text = "Touch Ended"
lblTapCount.text = String(touch.tapCount)
lblTouchCount.text = String(touches.count)
}
}
'개발자 넋두리 > 아이폰개발(Swift)' 카테고리의 다른 글
Swift 개발하면서.. 자질구레 하게 꿀팁들... (1) | 2025.01.24 |
---|---|
Swift Gesture(스와이프, 멀티스와이프)-Swipe 이벤트 따라하기 (0) | 2025.01.23 |
Swift 동영상 플레이 예제. (0) | 2025.01.21 |
Swift 오디오, 동영상 플레이 예제 소스 (0) | 2025.01.20 |
Swift 오류-this class is not key value coding-compliant for the key btnSize (4) | 2024.12.27 |