How can you add a UIGestureRecognizer to a UIBarButtonItem as in the common undo/redo UIPopoverController scheme on iPad apps?

后端 未结 15 1626
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 12:36

Problem

In my iPad app, I cannot attach a popover to a button bar item only after press-and-hold events. But this seems to be standard for

15条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 12:53

    @utopians answer in Swift 4.2

    @objc func myAction(_ sender: UIBarButtonItem, forEvent event:UIEvent) {
        let longPressed:Bool = (event.allTouches?.first?.tapCount).map {$0 == 0} ?? false
    
        ... handle long press ...
    }
    

提交回复
热议问题