当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。