core-data - 从 Core Data 加载图像使 NavigationView 过渡变得跳跃
问题描述
在我的 SwiftUI 应用程序中,当用户单击列表中的项目时,它会将用户带到详细信息视图。在详细信息视图中,我们需要显示从 Core Data 加载的图像。图像数据会在 NavigationView 过渡完成之前准备好,但 NavigationView 过渡会在图像出现时变得跳跃。
这是查看跳跃过渡的 GIF 图像:https ://gph.is/g/aQqBqRA
请在下面找到我的代码:
Image(uiImage: self.currentImage)
.resizable()
.aspectRatio(contentMode: .fit)
}
.onAppear {
DispatchQueue.main.async {
self.currentImage = UIImage(data: issue.photosArray[0].photoData!)!
}
}
如何修复跳跃的过渡?
解决方案
在动画开始之前.onAppear
调用,因此您加载的图像会在动画期间导致视图重建,从而导致观察效果。
如果图像在动画之前无法完全加载,那么最好推迟到动画完成后,比如
Image(uiImage: self.currentImage)
.resizable()
.aspectRatio(contentMode: .fit)
}
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.currentImage = UIImage(data: issue.photosArray[0].photoData!)!
}
}
推荐阅读
- r - 混淆矩阵给我“所有参数必须具有相同的长度”错误?
- java - 当相关方法具有多个预期异常时如何测试单个异常
- lotusscript - 从 Notes 数据库中提取代码作为文本
- r - 我将如何使用 if else 语句来制作 2 个数据集?
- java - 如何使用 for 命令指定列表的一部分
- haskell - Haskell-在函数和“where”语句中放置函数变量
- leaflet - 将 .getLatLng() 限制为 -90–90 和 -180–180
- computer-science - 具有将二进制转换为十进制的一种状态的图灵机
- android - 确保协程在没有取消的情况下完成
- javascript - 创建一个带有斜杠和反斜杠的函数