Here is a sample code for single and double action.
Note that a single click has a colon ( handleSingleTap: , but the double-click action is not ( handleDoubleTap )? This means that the selector takes an argument. Thus, in the functions below, we can check the sender of one tap, which would be useful if you assigned the tap function to many elements. If you have a colon, you must have parameters in the function.
override func viewDidLoad() { super.viewDidLoad() // Single Tap let singleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleSingleTap:") singleTap.numberOfTapsRequired = 1 self.view.addGestureRecognizer(singleTap) // Double Tap let doubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleDoubleTap") doubleTap.numberOfTapsRequired = 2 self.view.addGestureRecognizer(doubleTap) } func handleSingleTap(sender: AnyObject?) { print("Single Tap!") } func handleDoubleTap() { print("Double Tap!") }
Note: in this example, a single click action will be performed twice.
source share