gpt4 book ai didi

ios - 当我将.repeatsForever()添加到动画时,为什么Xcode会引发错误?

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

我正在尝试让 Activity 指示器在下载过程中旋转。由于某种原因,当我尝试使动画永远重复时,它在VStack代码的底部抛出了错误的方式。

这有效:

struct AddView: View {

@State var showActivitySpinner: Bool = false
@State var urlText: String = ""

var body: some View {
VStack{
Image(systemName: "arrow.2.circlepath.circle")
.resizable()
.frame(width: 80, height: 80)
.opacity(showActivitySpinner ? 1 : 0)
.rotationEffect(.degrees(showActivitySpinner ? 360 : 0))
.animation(.easeIn(duration: 1.0))

Spacer()
.frame(maxHeight: 100)

TextField("placeholder text", text: $urlText)
.textFieldStyle(RoundedBorderTextFieldStyle())
.font(Font.system(size: 16, design: .default))
.offset(y: -50)

Button(
action:{self.myFunction()},
label: {
HStack{
Image(systemName: "plus.circle.fill")
Text("Add")
.font(.title)
}
}
)
}
.padding()
.offset(y: -100)

}

但是,当我添加.repeatForever()时,xcode的VStack偏移量有问题。

"Extraneous argument label 'y:' in call"
到底是怎么回事?

最佳答案

您必须在.easeIn之前写动画。

将您的修饰符更正为:

.animation(Animation.easeIn(duration: 1.0).repeatForever(autoreverses: true))

您可能已经知道,SwiftUI(目前)并未指向正确的错误行。这就是为什么它指向偏移量。

关于ios - 当我将.repeatsForever()添加到动画时,为什么Xcode会引发错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58964044/

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