SwiftUI 应用程序中的 AWS S3 图像导致极度延迟?
因此,在我的应用程序中,我从 S3 URL 获取一些 S3 图像并在我的 SwiftUI 应用程序中渲染它们。 URL 看起来像这样,“test-image-name”大约 5 MB:
https://s3-bucket-name.s3.amazonaws.com/test-image-name
在我的 SwiftUI 应用程序内部,图像呈现如下:
Image(systemName: "camera")
.data(url: URL(string: "https://s3-bucket-name.s3.amazonaws.com/test-image-name")!)
.resizable()
.scaledToFill()
.maxHeight(150)
.clipped()
.onAppear() {
print("Image: \(URL(string: "https://s3-bucket-name.s3.amazonaws.com/test-image-name")!)")
}
或这样:
Image(systemName: "camera")
.data(url: URL(string: "https://s3-bucket-name.s3.amazonaws.com/test-image-name")!)
.resizable()
.scaledToFill()
.maxHeight(260)
.frame(width: UIScreen.main.bounds.width)
.clipped()
由于某种原因,当我在 SwiftUI 应用程序中没有这些图像块时SwiftUI 代码,应用程序运行平稳,但是一旦这些图像块包含在代码中(无论它们是否显示在屏幕上的视图中),就会出现极大的延迟,它会标记一分钟以上来注册触摸/拖累。在整个应用程序中,我有其他带有域的图像,不会导致任何延迟:
https://encrypted-tbn0.gstatic.com/images?q=xxxxxxxxxxxxxxxxxxxxxx
我在想也许 S3 获取时间很长,并且在 SwiftUI 应用程序中状态更改始终导致重新渲染,但我不确定。
不知道如何解决这个问题,非常感谢任何帮助!
so in my app, I'm fetching some S3 images from the S3 URL and rendering them in my SwiftUI app. The URL looks something like and 'test-image-name' is about 5 MB:
https://s3-bucket-name.s3.amazonaws.com/test-image-name
Inside of my SwiftUI app, the image is rendered like this:
Image(systemName: "camera")
.data(url: URL(string: "https://s3-bucket-name.s3.amazonaws.com/test-image-name")!)
.resizable()
.scaledToFill()
.maxHeight(150)
.clipped()
.onAppear() {
print("Image: \(URL(string: "https://s3-bucket-name.s3.amazonaws.com/test-image-name")!)")
}
or this way:
Image(systemName: "camera")
.data(url: URL(string: "https://s3-bucket-name.s3.amazonaws.com/test-image-name")!)
.resizable()
.scaledToFill()
.maxHeight(260)
.frame(width: UIScreen.main.bounds.width)
.clipped()
For some reason, when I don't have these Image blocks in the SwiftUI code, the app runs smoothly but as soon as these Image blocks are included in the code (regardless of whether they are presented or not in the views on the screen), there is extreme lag where it tags a minute plus to register touches/drags. Throughout the app, I have other images with domain that don't cause any lag whatsoever:
https://encrypted-tbn0.gstatic.com/images?q=xxxxxxxxxxxxxxxxxxxxxx
I was thinking maybe the S3 fetch time is long, and in SwiftUI apps state changes cause re-renders all the time, but I'm not sure.
Not sure how to fix this, any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论