在单元格中使用Texture(ASyncDisplayKit)

时间:2018-05-31 08:29:19

标签: swift asyncdisplaykit

我试图调整我单元格的组件,但它并没有按原样运行。我相信,我只是不了解ASLayoutSpec背后的一些简单想法,所以我很感激这里的任何帮助。

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

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

我所拥有的是asSoundIcon不是垂直居中的,而是我想要的更远的地方。

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

sorry for the colors

asSoundIcon

1 个答案:

答案 0 :(得分:1)

尝试删除行

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打破纹理&gt; v.2.3.4