【发布时间】:2021-06-07 17:07:49
【问题描述】:
我的解决方案很老套,坦率地说甚至不起作用,因为旋转循环会阻止其他同时发生的按钮动作被识别。我希望能够使用长按手势识别器,但这在 GCController 上不可用。
let dPadLeftButtonPressedChangedHandler = {
(dPadLeftButton: GCControllerButtonInput, value: Float, pressed: Bool) -> Void in
if dPadLeftButton.isPressed {
// No longer nil
self.moveLeft()
self.nanoTimer = DispatchTime.now()
while (dPadLeftButton.isPressed) {
let nanoTimerNow = DispatchTime.now()
// Thousandths of a second
let timeDifference = (nanoTimerNow.uptimeNanoseconds - self.nanoTimer!.uptimeNanoseconds) / UInt64(1000000)
// 200 / 1000 is .2 seconds
if timeDifference > 250 {
self.hardLeft()
self.nanoTimer = nil
break
}
}
}
}
controller?.extendedGamepad?.dpad.left.pressedChangedHandler = dPadLeftButtonPressedChangedHandler
【问题讨论】:
标签: swift button controller