當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Swift Never digitalCrownRotation(_:from:through:by:sensitivity:isContinuous:isHapticFeedbackEnabled:)用法及代碼示例

實例方法

digitalCrownRotation(_:from:through:by:sensitivity:isContinuous:isHapticFeedbackEnabled:)

通過更新指定的綁定來跟蹤 Digital Crown 旋轉。

聲明

func digitalCrownRotation<V>(
    _ binding: Binding<V>,
    from minValue: V,
    through maxValue: V,
    by stride: V.Stride? = nil,
    sensitivity: DigitalCrownRotationalSensitivity = .high,
    isContinuous: Bool = false,
    isHapticFeedbackEnabled: Bool = true
) -> some View where V : BinaryFloatingPoint, V.Stride : BinaryFloatingPoint

參數

binding

與用戶旋轉數字表冠時更新的值的綁定。

minValue

報告範圍的下限。

maxValue

報告範圍的上限。

stride

該值確定為 stride 的倍數。

sensitivity

用戶需要旋轉多少數字表冠才能在兩個整數之間移動。

isContinuous

控製報告的值是否在 minValuemaxValue 處停止,或者是否應該環繞。默認為 false

isHapticFeedbackEnabled

控製轉動 Digital Crown 時產生的觸覺反饋。默認為 true

詳述

當用戶在 Apple Watch 上轉動 Digital Crown 時,使用此方法接收您提供的綁定上的值。下麵的示例接收綁定值的更改,從 0.0minValue10.0maxValue0.1 遞增或遞減的步長取決於用戶轉動數字表冠的方向,如果用戶超過指定的邊界值,則翻轉:


struct DigitalCrown: View {
    @State private var crownValue = 0.0
    @State private var minValue = 0.0
    @State private var maxValue = 10.0
    @State private var stepAmount = 0.1


    var body: some View {
        Text("Received Value:\(crownValue, specifier: "%.2f")")
            .focusable()
            .digitalCrownRotation($crownValue,
                                  from: minValue,
                                  through: maxValue,
                                  by: stepAmount,
                                  sensitivity: .low,
                                  isContinuous: true)
    }
}

可用版本

watchOS 6.0+

相關用法


注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Never digitalCrownRotation(_:from:through:by:sensitivity:isContinuous:isHapticFeedbackEnabled:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。