Quentin F.
Quentin F.

Reputation: 17

Number of fingers touching screen (Swift 2.0)

I have a problem !

I want my iPhone displays how many fingers touch the screen... I used the touchesBegan and touchesEnded. My iPhone displays how many fingers touch the screen BUT ONLY when I touch simultaneously with fingers (2, 3 or 4...). I want it displays number of fingers while adding one or more fingers...

Thank you very much for your help...

PS: Sorry for my English

Upvotes: 1

Views: 1004

Answers (1)

Hawkydoky
Hawkydoky

Reputation: 194

UPDATE For Swift 3 :

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    super.touchesBegan(touches, with: event)
    var countTouch = event?.allTouches?.count

//Do whatever you want with that
}

If you want to know if it changed at any moment, do the same in touchesMoved and put it in an array, you'll be able to analyze it or just print it directly.

Like this :

var countTouch:[Int] = []

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    super.touchesBegan(touches, with: event)
    countTouch.append((event?.allTouches?.count)!) //Not really necessary

//Do whatever you want with that
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesMoved(touches, with: event)
    countTouch.append((event?.allTouches?.count)!)
}

Hope it helped someone, don't hesitate to edit or improve it. I'm a beginner in Swift, so it's totally possible there are mistakes.

Upvotes: 1

Related Questions