本文介绍了在 SwiftUI 中连续重复操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使文本字段等元素连续放大然后缩小?
How can I make an element such as a text field scale up and then down continuously?
我有这个:
struct ContentView : View {
@State var size:Double = 0.5
var body: some View {
ZStack {
Text("Hello!")
.padding()
.scaleEffect(size)
}
}
}
我知道我需要增加大小,然后在某种循环中减少它,但在 SwiftUI 中无法完成以下操作:
I know I need to increase size and then decrease it in some sort of loop but the following cannot be done in SwiftUI:
while true {
self.size += 0.8
sleep(0.2)
self.size -= 0.8
}
推荐答案
Animation.basic 已弃用.基本动画现在以其曲线类型命名:如线性等:
Animation.basic is deprecated. Basic animations are now named after their curve types: like linear, etc:
var foreverAnimation: Animation {
Animation.linear(duration: 0.3)
.repeatForever()
}
来源:https://forums.swift.org/t/swiftui-animation-basic-duration-curve-deprecated/27076
这篇关于在 SwiftUI 中连续重复操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!