有没有一种方法可以自动使用动画更改文本值?
我有一个加载屏幕,我想在其中显示一个通过动画自动更改其值的文本。
I have my logo rotating indefinitely without any button action
//logo
Image("reny")
.rotationEffect(.degrees(rotateDegree))
.onAppear(perform: {
withAnimation(Animation.linear(duration: 4).repeatForever(autoreverses: false)) {
self.rotateDegree = 360
}
})
I assumed it was possible to do the same for a text using a string array but it doesn't work
@State var texts = ["Find the Apartment you like", "send an application", "we'll approve you in secs baby!"]
@State var textIndex : Int = 0
//introduction text
Text(texts[textIndex]).bold()
.font(.title)
.onAppear(perform: {
withAnimation(Animation.linear(duration: 2).repeatForever(autoreverses: false)) {
textIndex += 1
}
})
does anybody know how to change the value of a text with an animation automatically?
我的目的是展示如何在此加载时间内使用该应用程序。
I have a loading screen where I want to show a text changing its value automatically with an animation.
I have my logo rotating indefinitely without any button action
//logo
Image("reny")
.rotationEffect(.degrees(rotateDegree))
.onAppear(perform: {
withAnimation(Animation.linear(duration: 4).repeatForever(autoreverses: false)) {
self.rotateDegree = 360
}
})
I assumed it was possible to do the same for a text using a string array but it doesn't work
@State var texts = ["Find the Apartment you like", "send an application", "we'll approve you in secs baby!"]
@State var textIndex : Int = 0
//introduction text
Text(texts[textIndex]).bold()
.font(.title)
.onAppear(perform: {
withAnimation(Animation.linear(duration: 2).repeatForever(autoreverses: false)) {
textIndex += 1
}
})
does anybody know how to change the value of a text with an animation automatically?
my intention is to show how to use the app during this loading time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种可能的方法 - 仅根据索引替换文本,并在出现后不断更改索引。
Tested with Xcode 13.4 / iOS 15.5
Main part:
and text itself
Here is a possible approach - just to replace Text depending on index and continuously change index after appear.
Tested with Xcode 13.4 / iOS 15.5
Main part:
and text itself
Test module on GitHub