[英]Long press animation with Swift UI
我有一个长按手势,突出显示另一个按钮。 代码如下所示:
@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
重音并返回更平滑的过渡? 目前它切换得相当突然。
.accentColor
不是动画修饰符,但是您可以使用以下方法实现相同的效果(据我所知)。
struct TestLongPressGesture: View {
@GestureState var highlight = false
var body: some View {
var longPress: some Gesture {
LongPressGesture(minimumDuration: 3)
.updating($highlight) { currentstate, gestureState, transaction in
transaction.animation = Animation.easeInOut(duration: 2.0)
gestureState = currentstate
}
}
return VStack {
Text("highlight!")
.gesture(longPress)
Divider()
Button("Button") { }
.font(Font.largeTitle.bold())
.foregroundColor(.white)
.colorMultiply(self.highlight ? .green : .blue)
.animation(.easeInOut, value: highlight)
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.