gpt4 book ai didi

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

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

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

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

asBackView 应该比 asTextLabel 高一点宽一点(可以),asSoundIcon 应该在 的右边>asBackView(例如,asBackView 右侧和 asSoundIcon 左侧之间的 4 个点),它应该垂直居中。

我所拥有的是 asSoundIcon 不是垂直居中的,它比我想要的更靠右。

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

sorry for the colors

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
}
}

附言layoutSpecBlock 在 Texture > v. 2.3.4 上损坏

关于swift - 在单元格中使用纹理 (ASyncDisplayKit),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50619904/

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