【发布时间】:2021-02-26 09:05:39
【问题描述】:
我正在使用 SwiftUI 构建一个手表应用程序。出于某种原因,我需要检查用户是否向上或向下旋转表冠,然后显示或隐藏一些 UI。
我只找到了digitalCrownRotation这个函数,它可以从表冠读取值,但我还没有弄清楚如何获取旋转方向。
任何提示将不胜感激。
更新数据 示例代码 我正在使用 digitalCrownRotation,但问题是滚动视图现在不滚动。
struct ContentView: View {
@State private var up = false
@State private var scrollAmount = 0.0
@State private var prevScrollAmount = 0.0
var body: some View {
ScrollView {
Text("""
Here you can find activities to practise your reading skills. Reading will help you to improve your understanding of the language and build your vocabulary.
The self-study lessons in this section are written and organised according to the levels of the Common European Framework of Reference for languages (CEFR). There are different types of texts and interactive exercises that practise the reading skills you need to do well in your studies, to get ahead at work and to communicate in English in your free time.
"""
)
}
.focusable(true)
.digitalCrownRotation($scrollAmount)
.onChange(of: scrollAmount) { value in
self.up = (value > prevScrollAmount)
self.prevScrollAmount = value
if up {
print("up")
} else {
print("down")
}
}
}
}
【问题讨论】:
标签: swift swiftui apple-watch watch watchos