투케이2K

190. (ios/swift) touchesBegan , touchesMoved , touchesEnded 사용해 디스플레이 터치 이벤트 감지 실시 본문

IOS

190. (ios/swift) touchesBegan , touchesMoved , touchesEnded 사용해 디스플레이 터치 이벤트 감지 실시

투케이2K 2022. 9. 14. 17:02
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT

 

[소스 코드]

    // MARK: - [사용자 터치 이벤트 발생 확인 실시]
    var touchCount = 0
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        // [터치 이벤트 값 초기화 실시]
        self.touchCount = 1
        
        // [로그 출력 실시]
        print("")
        print("===============================")
        print("[ViewController >> touchesBegan() :: 사용자 디스플레이 터치 이벤트 시작]")
        print("[touchCount :: \(self.touchCount)]")
        print("===============================")
        print("")
    }
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        // [터치 이벤트 값 추가 실시]
        self.touchCount = self.touchCount + 1
        
        // [로그 출력 실시]
        print("")
        print("===============================")
        print("[ViewController >> touchesMoved() :: 사용자 디스플레이 터치 이벤트 이동]")
        print("[touchCount :: \(self.touchCount)]")
        print("===============================")
        print("")
        
    }
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        // [터치 이벤트 값 초기화 실시]
        self.touchCount = 0
        
        // [로그 출력 실시]
        print("")
        print("===============================")
        print("[ViewController >> touchesEnded() :: 사용자 디스플레이 터치 이벤트 종료]")
        print("[touchCount :: \(self.touchCount)]")
        print("===============================")
        print("")
    }
    override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        // [터치 이벤트 값 초기화 실시]
        self.touchCount = 0
        
        // [로그 출력 실시]
        print("")
        print("===============================")
        print("[ViewController >> touchesCancelled() :: 사용자 디스플레이 터치 이벤트 취소]")
        print("[touchCount :: \(self.touchCount)]")
        print("===============================")
        print("")
    }
 

[결과 출력]


반응형
Comments