on single tap UIBarButton display toast and on double tap back action need to perform

前端 未结 3 780
南旧
南旧 2021-01-27 08:24

I have an UIBarButton in navigation bar, while clicking on back button (first tap) i need to display toast (like warning), on double tap i need to exit from the page in swift,

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-27 08:31

    Add an target-action on UIButton for the control event UIControlEventTouchDownRepeat, and do action only when the touch's tapCount is 2. Like below in Swift 3

    button.addTarget(self, action: #selector(multipleTap(_:event:)), for: UIControlEvents.touchDownRepeat)
    

    And Then add selector as below

    func multipleTap(_ sender: UIButton, event: UIEvent) {
        let touch: UITouch = event.allTouches!.first!
        if (touch.tapCount == 2) {
            // do action.
        }
    }
    

提交回复
热议问题