【发布时间】:2019-09-13 21:31:30
【问题描述】:
我刚刚切换到 xcode 的 GM 版本,从那以后我遇到了一个在我看来之前没有的问题。
我创建了问题的简化版本:
我有一个滚动视图,里面有几个元素。
我在蓝色方块上添加了动画状态,但我的印象是元素没有动画并且粗暴地改变状态。
我尝试使用滚动视图之外的元素(紫色方块),它可以工作
我不明白为什么动画不起作用有人有想法吗?
@State var Enter = false
var body: some View {
VStack {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 15) {
Rectangle()
.foregroundColor(Color.red)
.frame(width: 80, height: 80, alignment: .center)
Button(action: {
withAnimation(.easeInOut(duration: 1.12)) {
self.Enter = true
}
}) {
Rectangle()
.foregroundColor(Color.blue)
.frame(width: 80, height: 80, alignment: .center)
.opacity(self.Enter ? 0 : 1)
}
//.padding(.horizontal, self.Enter ? 50 : 10)
Rectangle()
.foregroundColor(Color.green)
.frame(width: 80, height: 80, alignment: .center)
.offset(x: self.Enter ? 30 : 0 , y: 0)
Rectangle()
.foregroundColor(Color.red)
.frame(width: 80, height: 80, alignment: .center)
}
.padding(.leading, 67 )
.padding(.trailing, 110)
// .padding(.top, (screen.height)/81.2)
.padding(.bottom, 10)
}
HStack {
Rectangle()
.foregroundColor(Color.purple)
.frame(width: 80, height: 80, alignment: .center)
.offset(x: self.Enter ? 80 : 0 , y: 0)
}
}
}
【问题讨论】:
标签: animation scrollview element swiftui