我制作了这个小动画,效果很好,只是主VStack
的"灰色背景"已经达到了他的最大值height
.
你认为有没有可能让image
出现/存在,而不是在不透明度上工作,这样当image
显示时,"灰色背景"可以扩展?
import SwiftUI
struct ExampleView: View {
@State private var isSowing = false
var body: some View {
VStack() {
HStack() {
Image("photo")
.onAppear { animateImage() }
VStack() {
Text("Name")
Text("Company")
}
Spacer()
}
Image("image")
.opacity(isSowing ? 1 : 0)
.offset(y: isSowing ? 0 : 80)
}
.background(Color.grey)
}
private func animateImage() {
withAnimation(.easeInOut.delay(1)) {
isSowing = true
}
}
}