gpt4 book ai didi

ios - 使用 Swift UI 长按动画

转载 作者:行者123 更新时间:2023-12-01 15:46:50 25 4
gpt4 key购买 nike

我有一个长按手势突出显示另一个按钮。代码如下所示:

@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不是动画修饰符,但是您可以使用以下方法实现相同的效果(只要我理解)。

demo

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)
}
}
}

关于ios - 使用 Swift UI 长按动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61073590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com