티스토리 뷰

Xcode(버전11.3)를 탭(Tap)과 터치(Touch) 연습 앱을 만든다:D

탭 카운트와 터치 카운트를 Label로 표시해준다.

- 탭 카운트(Tap Count) : 연속으로 탭한 횟수

- 터치 카운트(Touch Count) : 몇개의 손가락으로 터치

iOS 시뮬레이터에서는 option버튼을 누르면 손가락 두 개로 터치 할 수 있다.

 

 

 

- 멀티 터치(Multiple Touch) 활성화

스토리보드에서 아이폰 모양의 화면인 뷰(View)를 선택 -> Attributes inspector -> 'Multiple Touch' Check

 

 

 

- 스토리보드 화면 구성

1) Lable

'Tap / Touch', 'Message :', Label, 'Tap Count :', Label, 'Touch Count :', Label

 

 

 

- 아웃렛 변수 추가

Label -> 'txtMessage'

Label -> 'txtTapsLevel'

Label -> 'txtTouchsLevel'

 

 

 

전체 소스 보기

//
//  ViewController.swift
//  day200102_TapTouch
//
//  Created by 무니 on 2020/01/02.
//  Copyright © 2020 com.mooni. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet var txtMessage: UILabel!
    @IBOutlet var txtTapsLevel: UILabel!
    @IBOutlet var txtTouchsLevel: 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
        
        txtMessage.text = "Touches Began"
        // touches 세트 안에 포함된 터치의 개수를 출력
        txtTapsLevel.text = String(touch.tapCount)
        // 터치 객체들 중 첫번째 객체에서 탭의 개수를 가져와 출력
        txtTouchsLevel.text = String(touches.count)
    }
    
    // 터치된 손가락이 움직였을 때 호출
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        let touch = touches.first! as UITouch
        
        txtMessage.text = "Touches Moved"
        txtTapsLevel.text = String(touch.tapCount)
        txtTouchsLevel.text = String(touches.count)
    }
    
    // 화면에서 손가락을 떼엇을 때 호출
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        let touch = touches.first! as UITouch
               
        txtMessage.text = "Touches Ended"
        txtTapsLevel.text = String(touch.tapCount)
        txtTouchsLevel.text = String(touches.count)
    }

}

 

 

 

시뮬레이터 결과 화면

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함