gpt4 book ai didi

ios - ASNetworkImageNode gif 未加载

转载 作者:行者123 更新时间:2023-11-30 11:20:20 25 4
gpt4 key购买 nike

我正在创建自定义节点来显示带有播放和暂停按钮的 gif 文件。以下是我的代码。

import Foundation
import AsyncDisplayKit

class GifNode: ASCellNode {
var gifImageNode:ASNetworkImageNode = {
let node = ASNetworkImageNode()
node.contentMode = .scaleAspectFit
node.shouldRenderProgressImages = true
return node
}()
var playImage: ASImageNode = {
let node = ASImageNode()
node.contentMode = .scaleAspectFit
node.style.height = ASDimensionMakeWithPoints(30)
node.style.height = ASDimensionMakeWithPoints(30)
node.backgroundColor = .gray
node.image = #imageLiteral(resourceName: "play")
return node
}()

init(model:GifContent)
{
super.init()

self.automaticallyManagesSubnodes = true

let width = UIScreen.main.bounds.size.width
let height = (width * model.height) / model.width

gifImageNode.url = URL(string: "https://i.pinimg.com/originals/07/44/38/074438e7c75034df2dcf37ba1057803e.gif")
gifImageNode.style.width = ASDimensionMake(width)
gifImageNode.style.height = ASDimensionMake(height)

gifImageNode.animatedImagePaused = true

gifImageNode.addTarget(self, action: #selector(self.toggleGifPlay), forControlEvents: .touchUpInside)
}

@objc func toggleGifPlay()
{
self.gifImageNode.animatedImagePaused = !self.gifImageNode.animatedImagePaused
self.playImage.isHidden = !self.gifImageNode.animatedImagePaused
}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let playButtonCenterSpec = ASCenterLayoutSpec(centeringOptions: .XY, sizingOptions: .minimumXY, child: self.playImage)
return ASOverlayLayoutSpec(child: gifImageNode, overlay: playButtonCenterSpec)
}
}

当我尝试在另一个 ASCellNode 中使用 gif 节点时,它不会呈现。我可以看到播放按钮,但看不到实际的 gif 文件。如果我尝试使用相同的控件加载 jpeg,它工作正常。如果我尝试直接加载 gif 而不是使用上面的类,它也可以正常工作。

不确定我是否遗漏了什么。

最佳答案

我测试了您的应用程序,但默认情况下您的动画被禁用gifImageNode.animatedImagePaused = true

关于ios - ASNetworkImageNode gif 未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51334234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com