swift UIGestureRecognizer单指多指触控
习惯用代码说话
//设置“定位”单击和双击的效果 func setLocationButtonClickEvent(){ var gr1:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("handleTapGesture:")) var gr2:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("handleTapGesture:")) gr1.numberOfTapsRequired = 1 gr1.requireGestureRecognizerToFail(gr2)//这里保证双击的时候不会出发单击时间 gr2.numberOfTapsRequired = 2 self.relocationButton.addGestureRecognizer(gr1) self.relocationButton.addGestureRecognizer(gr2) }
func handleTapGesture(sender:UITapGestureRecognizer){ let touchCount:Int = sender.numberOfTapsRequired switch touchCount { case 1: println("单击") case 2: println("双击") default:println("") } }