【发布时间】:2018-12-27 00:20:09
【问题描述】:
我正在我的 Xcode 项目中实现一个名为 Skeleton View 的 API。有时,当应用程序第一次加载时,加载 UI 元素需要更长的时间,因为数据来自 JSON,如果用户使用 4G 甚至是糟糕的互联网,将仍然是一个空白字段。此外,使用此 API,它在每个未接收数据的 UIElement 上显示为灰色视图动画占位符。
但是,我不知道如何检查 UIImage 何时接收到能够移除骨架效果并呈现图像的值。我会在下面发布一些图片。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellID") as! TableViewCell
let model = arrCerveja[indexPath.row]
cell.labelName.text = model.name
cell.labelDetail.text = "Teor alcoólico: \(model.abv)"
let resource = ImageResource(downloadURL: URL(string: "\(model.image_url)")!, cacheKey: model.image_url)
if cell.imageViewCell.image != nil {
cell.imageViewCell.kf.setImage(with: resource)
cell.imageViewCell.hideSkeleton()
}else{
cell.imageViewCell.showAnimatedGradientSkeleton()
//The placeholder still there even when the images already got downloaded
//What I wanted was, while the UIImageView has no value, the placeholder
//persists, but when receive the image the placeholder should be dismissed.
}
return cell
}
这就是我在 UIImages 上得到的(它有一个模糊动画经过):
我面临的问题是如何在每个图像加载后消除这种效果?
【问题讨论】:
-
如果您要复制自己的问题stackoverflow.com/questions/51411101/…,请删除其中一个。
-
我刚刚删除了另一个问题,感谢您记住我。兄弟,你能给我一个解决方案吗?
标签: ios swift xcode placeholder