我有一个长按手势,可以高亮显示另一个按钮。代码如下:
@GestureState var highlight = false
var body: some View {
var longPress: some Gesture {
LongPressGesture(minimumDuration: 3)
.updating($highlight) { currentstate, gestureState, transaction in
gestureState = currentstate
transaction.animation = Animation.easeInOut(duration: 2.0)
}
}
Text("highlight!")
.gesture(longPress)
Button(...) { ... }
.accentColor(self.highlight ? .green : .none)
}
我该如何确保从.none
强调到.green
强调的过渡更加平滑,以及从.green
强调回到.none
的过渡也更加平滑?目前切换相对突然。
easeOut
动画。而且在暗模式下,乘法产生的颜色相当紫色,而非绿色。 - vasily.animation(.easeInOut)
在colorMultiply
之后。 - vasily