- By default a UIView can only receive one touch.
- Enabling Multiple Touch allows the UIView to receive more than one touch.
- In code you reference the multipleTouchEnabled property
Example
In this example the tan area has Multiple Touch on while the white area does not.Code
class ViewController: UIViewController { @IBOutlet weak var touchesLabel: UILabel! @IBOutlet weak var touchPointsLabel: UILabel! override func touchesBegan(_ touches: Set, with event: UIEvent?) { // Number of Touches touchesLabel.text = "\(touches.count)" // Coordinates of the Touches var coordinates = "" var touchNumber = 0 for touch in touches { touchNumber = touchNumber + 1 let point = touch.location(in: view) coordinates = coordinates + "Touch \(touchNumber): [\(point.x), \(point.y)] \n" } touchPointsLabel.text = coordinates } }
- Apple Docs: multipleTouchEnabled
(Xcode 8, Swift 3.0)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.