ios - 多个动画在 SwiftUI 中无法按预期工作
问题描述
我想用永远重复的动画创建一个脉动的圆圈。当动画方向改变时,它应该有大小的渐变和颜色的瞬间变化。我有两个不同的动画,但只有最后一个对两者都有影响(大小和颜色变化)。
struct SwiftUIView: View {
@State private var animationStarted = false
let side = UIScreen.main.bounds.size.width
let animation1 = Animation.easeInOut(duration: 0.3).delay(5.7)
.repeatForever(autoreverses: true)
let animation2 = Animation.easeInOut(duration: 6)
.repeatForever(autoreverses: true)
var body: some View {
HStack {
VStack {
HStack {
Circle()
.foregroundColor(self.animationStarted ? Color.pink : Color.blue)
.animation(animation1)
.frame(width: self.animationStarted ? 10 : side, height: self.animationStarted ? 10 : side)
.animation(animation2)
.onAppear {
self.animationStarted.toggle()
}
}
}.frame(height: side)
}.frame(width: side)
}
}
解决方案
推荐阅读
- wordpress - 简码中的 WP_Error 以显示条款
- nlp - 将拼写错误的单词转换为实际单词
- asp.net - 在容器化的 .NET Framework Web 应用程序中更改配置的最佳方法是什么?
- spring-boot - 管理每个套接字消息的数据库调用 Spring Boot
- django - 如何计算 Django 中两个关系之间的数据?
- python - 如何对热图进行排序以显示最高相关性?
- reactjs - React 测试库 - 屏幕调试提供与浏览器不同的输出
- php - 无法使用 php 插入 MySQL 数据库
- angular - 如何更改角垫扩展面板方向
- electron - 如何检查电子中是否按下了某个键?