Hello,
Is there a way how to detect long press on arrow on new Siri remote? UILongPressGestureRecognizer detect only presses on select button (small circle). How we can detect long press on the directional wheel?
Hello,
Is there a way how to detect long press on arrow on new Siri remote? UILongPressGestureRecognizer detect only presses on select button (small circle). How we can detect long press on the directional wheel?
There is not but I found a way around it.
private var arrowLongPressWorkItem: DispatchWorkItem?
override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
for press in presses {
switch press.type {
case .leftArrow:
createArrowLongPressWorkItem(.left)
case .rightArrow:
createArrowLongPressWorkItem(.right)
default:
super.pressesBegan(presses, with: event)
}
}
}
override func pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
for press in presses {
switch press.type {
case .leftArrow, .rightArrow:
arrowLongPressWorkItem?.cancel()
self.arrowLongPressGesture(.cancelled)
default:
super.pressesCancelled(presses, with: event)
}
}
}
override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
for press in presses {
switch press.type {
case .leftArrow, .rightArrow:
self.arrowLongPressWorkItem?.cancel()
self.arrowLongPressGesture(.ended)
default:
super.pressesEnded(presses, with: event)
}
}
}
private func createArrowLongPressWorkItem(_ direction: GCControllerDirectionPad.AxisState) {
let workItem = DispatchWorkItem { [weak self] in
// Some Action
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: workItem)
arrowLongPressWorkItem = workItem
}
private func arrowLongPressGesture(_ gestureState: UIGestureRecognizer.State) {
let longPressGesture = UILongPressGestureRecognizer(
target: self,
action: #selector(handleLongPress))
longPressGesture.state = gestureState
handleLongPress(gestureRecognizer: longPressGesture)
}