技术文章分类(180)

技术随笔(11)

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("")
        }
    }

 

posted @ 2014-07-08 21:46  坤哥MartinLi  阅读(415)  评论(0编辑  收藏  举报