AsyncDisplayKey - stacklayout犯规在屏幕上显示
问题描述:
我尝试创建内部cellnode stacklayout,但没有在屏幕上显示AsyncDisplayKey - stacklayout犯规在屏幕上显示
class Node: ASCellNode {
let blackNode = ASDisplayNode()
let blueNode = ASDisplayNode()
override init() {
super.init()
self.addSubnode(blueNode)
self.addSubnode(blackNode)
}
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
blackNode.backgroundColor = .black
blueNode.backgroundColor = .blue
let contentStackSpec = ASStackLayoutSpec(direction: .horizontal,
spacing: 40,
justifyContent: .start,
alignItems: .center,
children: [blackNode, blueNode])
contentStackSpec.style.minWidth = ASDimensionMakeWithPoints(60.0);
contentStackSpec.style.maxHeight = ASDimensionMakeWithPoints(40.0);
return ASRelativeLayoutSpec(horizontalPosition: .center, verticalPosition: .center, sizingOption: .init(rawValue: 0), child: contentStackSpec)
}
}
我在做什么错?
答
我认为您应该使用ASInsetLayoutSpec
来显示ASStackLayoutSpec
而不是ASRelativeLayoutSpec
。
下面是一个使用ASInsetLayoutSpec
显示ASStackLayoutSpec
你定的代码执行:
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
blackNode.backgroundColor = .black
blueNode.backgroundColor = .blue
let contentStackSpec = ASStackLayoutSpec(direction: .horizontal,
spacing: 40,
justifyContent: .start,
alignItems: .center,
children: [blackNode, blueNode])
contentStackSpec.style.minWidth = ASDimensionMakeWithPoints(60.0);
contentStackSpec.style.maxHeight = ASDimensionMakeWithPoints(40.0);
let cardInsetSpec : ASInsetLayoutSpec = ASInsetLayoutSpec(insets: UIEdgeInsetsMake(5, 5, 5, 5), child: contentStackSpec)
return cardInsetSpec
}
也许一些错误ASRelativeLayoutSpec,试图返回'contentStackSpec'测试。 – Bimawa
而我没有看到任何规则来调整blueNode和blackNode的大小。 – Bimawa