3

I want to track down the position of my fingers in a UIViewController. I implemented this with the following function and this is working great!

override func viewDidLoad() {

    view.userInteractionEnabled = true
    view.multipleTouchEnabled = true

    super.viewDidLoad()
}


override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
  //Create subview and place it under your finger.
}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
  //Here methods which tracks the moves of the finger and updates the subviews position.
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
  //Remove subview from superview overhere.
}

I have two issues:

  1. When I press more than 5 fingers on the screen, touchesBegin/touchesMoved/touchesEnded will not be called anymore. Even when I place 6 fingers and remove 1.
  2. Sometimes touchesBegan is called from random positions on my screen. TouchesEnded is called for the same point after that.

Should I implement this on another way? I also tried it using UIGestureRecognizer but without success.

I added this function

override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
}

And this is called when I tap the 6th finger on the screen.

Bas
  • 780
  • 5
  • 17

0 Answers0