在单元格中使用纹理 (ASyncDisplayKit)

Using Texture (ASyncDisplayKit) in cells

我正在尝试对齐单元格的组件,但效果不佳。我相信,我只是不明白 ASLayoutSpec 背后的一些简单想法,所以我很感激这里的任何帮助。

我有一个单元格(当然是 ASCellNode),它由 ASTextNode(asTextLabel)、ASDisplayNode(asBackView,它只是带有圆角的 textLabel 的背景)和 asImageNode(asSoundIcon).

asBackView 应该比 asTextLabel 高一点宽一点(它有效),并且 asSoundIcon 应该在 asBackView 的右侧(比如,4 asBackView右边和asSoundIcon左边之间的点),垂直居中。

我得到的是 asSoundIcon 不是垂直居中,它比我想要的更靠右。

我尝试了很多选项,这只是其中之一,我不明白为什么我的水平间距不起作用,以及如何垂直对齐asSoundIcon

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {

    asSoundIcon.style.preferredSize = CGSize(width: 16, height: 16)
    asSoundIcon.style.maxSize = CGSize(width: 16, height: 16)
    asSoundIcon.style.minSize = CGSize(width: 16, height: 16)
    asBackView.style.minSize = CGSize(width: 30, height: 48)
    asTextLabel.style.minSize = CGSize(width: 30, height: 15)
    asTextLabel.style.maxWidth = ASDimension(unit: .points, value: screenWidth - 50)

    let asBackViewLayout = ASInsetLayoutSpec(insets: UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 24), child: self.asBackView)

    let asTextLabelLayout = ASInsetLayoutSpec(insets: UIEdgeInsets(top: 6, left: 12, bottom: 6, right: 36), child: asTextLabel)

    let asNewCenterTextLabelLayout = ASCenterLayoutSpec(horizontalPosition: .start, verticalPosition: .center, sizingOption: .minimumWidth, child: asTextLabelLayout)

    let asOverlayLayout = ASOverlayLayoutSpec(child: asNewCenterTextLabelLayout, overlay: asBackViewLayout)

    let asSoundVerticalLayout = ASRelativeLayoutSpec(horizontalPosition: .start, verticalPosition: .center, sizingOption: .minimumSize, child: asSoundIcon)

    let asSoundLayout = ASStackLayoutSpec(direction: .horizontal, spacing: 0.0, justifyContent: .start, alignItems: .start, flexWrap: .noWrap, alignContent: .start, lineSpacing: 0.0, children: [asOverlayLayout, asSoundVerticalLayout])

    return asSoundLayout
}

尝试删除行

let asSoundVerticalLayout = ASRelativeLayoutSpec(horizontalPosition: .start, verticalPosition: .center, sizingOption: .minimumSize, child: asSoundIcon)

并更改下一行:

let asSoundLayout = ASStackLayoutSpec(direction: .horizontal, spacing: 0.0, justifyContent: .start, alignItems: .center, flexWrap: .noWrap, alignContent: .start, lineSpacing: 0.0, children: [asOverlayLayout, asSoundIcon])

UPD

我尝试做一个简单的project

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    viewNode.automaticallyManagesSubnodes = true
    viewNode.backgroundColor = UIColor.blue

    let asBackView = ASDisplayNode()
    asBackView.backgroundColor = UIColor.gray
    let asTextLabel = ASTextNode()
    asTextLabel.attributedText = NSAttributedString.init(string: "Cum contencio studere, omnes lunaes perdere audax, velox animalises.", attributes: [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 15)])
    asBackView.automaticallyManagesSubnodes = true
    asBackView.style.flexGrow = 1
    asBackView.style.flexShrink = 1
    asBackView.layoutSpecBlock = { asDisplayNode, asSizeRange in
        let asInsetSpec = ASInsetLayoutSpec(insets: UIEdgeInsetsMake(6, 12, 6, 36), child: asTextLabel)
        return asInsetSpec
    }

    let asSoundIcon = ASNetworkImageNode(cache: ASPINRemoteImageDownloader.shared(), downloader: ASPINRemoteImageDownloader.shared())
    asSoundIcon.setURL(URL.init(string: "https://www.shareicon.net/data/2017/02/09/878596_music_512x512.png"), resetToDefault: false)
    asSoundIcon.style.preferredSize = CGSize(width: 50,height: 50)
    viewNode.layoutSpecBlock = { node, constrainedSize in
        let asSoundInsetsSpec = ASInsetLayoutSpec(insets: UIEdgeInsetsMake(5, 5, 5, 5), child: asSoundIcon)
        let asStackLayout = ASStackLayoutSpec(direction: .horizontal, spacing: 0, justifyContent: .start, alignItems: .center, children: [asBackView, asSoundInsetsSpec])
        return asStackLayout
    }
}

P.S。 layoutSpecBlock 在 Texture > v. 2.3.4

上损坏