If you’d like to detect a long press on a UIButton or just for a view that has no buttons – it’s pretty easy. There is one simple gotcha, however. You’ll trigger your selector twice. Once when detected (down on the glass pad Apple TV remote), and again on the pad’s release.
So you’ll need to set a BOOL for knowing what the state is. Easy enough.
fileprivate var longDown: Bool = false override func viewDidLoad() { super.viewDidLoad() let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPress(longPressGestureRecognizer:))) view.addGestureRecognizer(longPressGestureRecognizer) } func longPress(longPressGestureRecognizer : UILongPressGestureRecognizer) { // I fire on the down and also on the release. if longDown == false { longDown = true print("long press down.") } else { longDown = false print("long press up.") } }
I would not have thought that the gesture would be triggered twice on hardware, but it does.