是否可以使用swiftUI隐藏watchOS上的数字皇冠指示器

问题描述 投票:0回答:1

我使用 Apple Watch 和 swiftUI 一段时间了,现在遇到了一些问题。

我希望在手表屏幕上不显示指示器的情况下访问数字表冠旋转值。我使用 swiftUI 连接到表冠没有问题,但我似乎无法隐藏或删除它所链接的指示器。

截至今天我的代码是:

struct TestView: View {
@State var scrollAmount = 0.0

var body: some View {
            containerView
                .focusable(true)
                .digitalCrownRotation($scrollAmount,
                                      from: 0,
                                      through: 1,
                                      by: 0.05,
                                      sensitivity: .low,
                                      isContinuous: false,
                                      isHapticFeedbackEnabled: true)
       }
    }

容器视图是视图的通用名称,而不是滚动视图,因此我无法应用

(showsIndicators: false)
。 正如我所说,接收scrollAmount 上的值没有问题。但每次旋转表冠时,屏幕上都会弹出指示器。 我尝试设置
.accentColor(.clear)
但它什么也没做,指示器仍然显示为绿色。

我是否遗漏了什么或做错了什么?我不知道如何告诉系统不要显示表冠指示器。

欢迎任何帮助或提示。

swift user-interface swiftui apple-watch watchos
1个回答
0
投票

HackingWithSwift
上找到了这个 scrollIndicators 修饰符,这对我有用。

struct ContentView: View {
    var body: some View {
        List(1..<100) { i in
            Text("Row \(i)")
        }
        .scrollIndicators(.hidden)
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.