返回 Skill 列表
extension
分类: 开发与工程无需 API Key

"gestures"

tvOS手势模式:使用onMoveCommand、onPlayPauseCommand、onExitCommand和滑动识别处理Siri Remote输入。在实现tvOS输入处理、遥控器交互或基于焦点的手势时使用。触发条件:手势、Siri Remote、onMoveCommand、滑动、遥控。

person作者: jakexiaohubgithub

Gestures (tvOS)

tvOS does NOT support touch gestures. All input comes from the Siri Remote.

Siri Remote Commands

DIRECTIONAL INPUT:

.onMoveCommand { direction in
    switch direction {
    case .up: moveUp()
    case .down: moveDown()
    case .left: moveLeft()
    case .right: moveRight()
    @unknown default: break
    }
}

PLAY/PAUSE BUTTON:

.onPlayPauseCommand {
    togglePlayback()
}

MENU/BACK BUTTON:

.onExitCommand {
    dismiss()
}

SELECT (CLICK) BUTTON:

  • Handled automatically by Button tap actions
  • Use .onTapGesture only for non-button focusable views

LONG PRESS:

.onLongPressGesture(minimumDuration: 0.5) {
    showContextOptions()
}

Swipe Recognition (Siri Remote touchpad)

.gesture(
    DragGesture(minimumDistance: 50)
        .onEnded { value in
            if abs(value.translation.width) > abs(value.translation.height) {
                if value.translation.width > 0 {
                    swipeRight()
                } else {
                    swipeLeft()
                }
            }
        }
)

NOT Available on tvOS

  • No pinch gestures
  • No rotation gestures
  • No multi-touch
  • No 3D Touch / Force Touch
  • No pencil input
  • No drag and drop

Rules

  1. Primary interaction is focus movement + select — not swipe
  2. Use onMoveCommand for directional navigation, not drag gestures
  3. Always handle onExitCommand for back navigation
  4. Siri Remote swipes are secondary — focus navigation is primary
  5. All interactive elements must work with focus + select pattern