0

I have two views in a ViewController that perform specific actions when touched down. If I keep one of them pressed with one finger and touch the same view with another finger, nothing happens. The "ok" test below doesn't appear.

I override the method touchesBegan to perform the actions:

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

    print("ok")
    if let touch = touches.first{
        let viewTag = touch.view!.tag
        if viewTag == 101 {
            // my action for view 1
        } else if viewTag == 102 {
            // my action for view 2
        }
    }
    super.touchesBegan(touches, withEvent: event)
}

Edit

I'm already using multipleTouchEnabled = true

msampaio
  • 3,394
  • 6
  • 33
  • 53

3 Answers3

1

You have to enable multiple touches on your view:

self.view.multipleTouchEnabled = true;
Diego
  • 577
  • 4
  • 14
1

From Documentation:

multipleTouchEnabled

A Boolean value that indicates whether the receiver handles multi-touch events.

When set to YES, the receiver receives all touches associated with a multi-touch sequence. When set to NO, the receiver receives only the first touch event in a multi-touch sequence. The default value of this property is NO.

Other views in the same window can still receive touch events when this property is NO. If you want this view to handle multi-touch events exclusively, set the values of both this property and the exclusiveTouch property to YES.

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
0

The multipleTouchEnabled = true must be set in both views, not only the main one.

Put this code in the viewDidLoad:

let tags = [101, 102]
for v in view.subviews {
    if tags.contains(v.tag) {
        v.multipleTouchEnabled = true
    }
}
msampaio
  • 3,394
  • 6
  • 33
  • 53