ios - SwiftUI:在填充的水平图像中制作 y 偏移的永久动画
问题描述
我正在尝试通过它的 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
}
}
}
推荐阅读
- go - libswscale bad dst 图像指针 cgo
- vue.js - 在饼图底部显示最大值 - highcharts
- sql - 每天在 SQL 中获取汇总结果
- node.js - 来自 GKE 的 PubSub:PERMISSION_DENIED
- c# - 该代码仅创建最后一个复选框,我应该做些什么不同或添加?
- node.js - 使用 NodeJs 为 mocha 生成报告
- php - 谷歌折线图不使用 PHP 显示 MySQL 查询
- google-cloud-platform - 如何上传我自己的部署自定义 zip?
- c - V4L2 - 设备不触发 epoll 事件
- vba - 按子文件夹和发送月份计算共享邮箱中的电子邮件