问题描述
我想根据箭头旋转以圆周运动为红色和绿色圆圈设置动画。我可以做到这一点,但这里是棘手的部分:我还想通过按下另一组按钮来旋转圆圈,并且它们需要动画,就好像它们属于另一个圆圈一样。同样的谜题出现在游戏“机械之王”的监狱情节中。
这很难解释,所以如果你有时间,请运行我的代码并观看 Machinarium 监狱拼图的视频:)
我猜在 swiftui 游戏“flipinity”中采用了类似的方法。任何帮助表示赞赏。对不起,代码太乱了:)
var body: some View {
ZStack {
vstack {
HStack {
ZStack {
Circle()
.fill(Color.green)
.frame(width: 40,height: 40)
.offset(x: -100)
.rotationEffect(.degrees(degree1))
.animation(Animation.eaSEOut(duration: 1))
Circle()
.fill(Color.red)
.frame(width: 40,height: 40)
.offset(x: -50,y: -86)
.rotationEffect(.degrees(degree1))
.animation(Animation.eaSEOut(duration: 1))
Circle()
.fill(Color.green)
.frame(width: 40,height: 40)
.offset(x: 50,height: 40)
.offset(x: 100,y: 0)
.rotationEffect(.degrees(degree1))
.animation(Animation.eaSEOut(duration: 1))
Circle()
.fill(Color.red)
.frame(width: 40,y: 86)
.rotationEffect(.degrees(degree1))
.animation(Animation.eaSEOut(duration: 1))
Circle()
.fill(Color.green)
.frame(width: 40,y: 86)
.rotationEffect(.degrees(degree1))
.animation(Animation.eaSEOut(duration: 1))
HStack(spacing: 20){
Image("left")
.resizable()
.scaledToFit()
.frame(width: 80,height: 80)
.rotationEffect(.init(degrees: 285))
.offset(x: -75,y: -90)
.onTapGesture(perform: {
degree1 -= 60
x = true
y = false
z = false
})
Image("right")
.resizable()
.scaledToFit()
.frame(width: 80,height: 80)
.rotationEffect(.init(degrees: 245))
.offset(x: -175,y: 90)
.onTapGesture(perform: {
degree1 += 60
x = true
y = false
z = false
})
}
}
.offset(x: 48,y: -100)
ZStack {
Circle()
.fill(Color.red)
.frame(width: 40,height: 40)
.offset(x: -100)
.rotationEffect(.degrees(degree2))
.animation(Animation.eaSEOut(duration: 1))
Circle()
.fill(Color.red)
.frame(width: 40,y: -86)
.rotationEffect(.degrees(degree2))
.animation(Animation.eaSEOut(duration: 1))
Circle()
.fill(Color.red)
.frame(width: 40,y: 0)
.rotationEffect(.degrees(degree2))
.animation(Animation.eaSEOut(duration: 1))
Circle()
.fill(Color.green)
.frame(width: 40,y: 86)
.rotationEffect(.degrees(degree2))
.animation(Animation.eaSEOut(duration: 1))
HStack(spacing: 20){
Image("left")
.resizable()
.scaledToFit()
.frame(width: 80,height: 80)
.rotationEffect(.init(degrees: 116))
.offset(x: 166,y: 100)
.onTapGesture(perform: {
degree2 -= 60
x = false
y = true
z = false
})
Image("right")
.resizable()
.scaledToFit()
.frame(width: 80,height: 80)
.rotationEffect(.init(degrees: 60))
.offset(x: 62,y: -100)
.onTapGesture(perform: {
degree2 += 60
x = false
y = true
z = false
})
}
}
.offset(x: -40,y: -100)
}
ZStack {
Circle()
.fill(Color.green)
.frame(width: 40,height: 40)
.offset(x: 50,y: 86)
.rotationEffect(.degrees(degree3))
.animation(Animation.eaSEOut(duration: 1))
Circle()
.fill(Color.red)
.frame(width: 40,height: 40)
.offset(x: -50,y: 86)
.rotationEffect(.degrees(degree3))
.animation(Animation.eaSEOut(duration: 1))
HStack(spacing: 20){
Image("right")
.resizable()
.scaledToFit()
.frame(width: 80,height: 80)
.rotationEffect(.init(degrees: 240))
.offset(x: -60,y: 100)
.onTapGesture(perform: {
degree3 += 60
x = false
y = false
z = true
})
Image("left")
.resizable()
.scaledToFit()
.frame(width: 80,height: 80)
.rotationEffect(.init(degrees: 116))
.offset(x: 60,y: 100)
.onTapGesture(perform: {
degree3 -= 60
x = false
y = false
z = true
})
}
}
.offset(x: 4,y: -102)
}
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)