我正在尝试通过它的y轴为“行”内的图像设置动画,以使您看起来该视图将在整个图像中缓慢地垂直滚动。完成后,它会回溯。我希望这是有道理的。我正在尝试通过以下代码进行操作:
var body: some View {
ZStack {
HStack {
GeometryReader { geometry in
WebImage(url: self.url)
.renderingMode(.original)
.resizable()
.placeholder {
ImageStore.shared.image(name: "exploras-icon")
}
.aspectRatio(contentMode: .fill)
.animate {
// animate by y offset within bounds of HStack
}
}
}
.frame(height: 140)
.clipped()
}
}
非常感谢任何帮助/指导!
这里是可能方法的演示。经过Xcode 11.4 / iOS 13.4的测试]
struct TestAutoScrollImage: View {
@State private var isActive = false
var body: some View {
GeometryReader { gp in
HStack {
Image("large_image")
}
.frame(width: gp.size.width, height: gp.size.height, alignment: self.isActive ? .bottom : .top)
}
.edgesIgnoringSafeArea([.top, .bottom])
.animation(Animation.linear(duration: 5).repeatForever())
.onAppear {
self.isActive = true
}
}
}