我正在尝试将嵌套的ASStackLayoutSpec
与AsyncDisplayKit一起使用
所以我要创建一个带有头像的垂直ASStackLayoutSpec
和另一个带有用户名,时间戳和文本的水平ASStackLayoutSpec
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
// HEADER with username and timestamp
let spacer = ASLayoutSpec()
spacer.style.flexGrow = 1
let headerStackSpec = ASStackLayoutSpec.horizontal()
headerStackSpec.spacing = 2
headerStackSpec.alignItems = .baselineFirst
headerStackSpec.children = [userNode, spacer, timestampNode]
// CONTENT - HEADER and text
let contentStackSpec = ASStackLayoutSpec.vertical()
contentStackSpec.spacing = 2
contentStackSpec.children = [headerStackSpec, messageNode]
// MAIN - avatar and CONTENT
let mainStackSpec = ASStackLayoutSpec.horizontal()
mainStackSpec.spacing = 9
mainStackSpec.children = [avatarNode, contentStackSpec]
return ASInsetLayoutSpec(insets: UIEdgeInsets(top: 2, left: 10, bottom: 2, right: 10), child: mainStackSpec)
}
但是结果却不是我所期望的
看起来文本会达到无穷大,无法正确换行。时间戳也可能在右侧之外。
我尝试了
.alignItems
和.justifyContent
的不同组合,但无法正常工作。 最佳答案
尝试以下属性:
contentStackSpec.style.flexShrik = 1
messageNode.style.flexShrik = 1
contentStackSpec.children = [headerStackSpec, messageNode]
关于ios - 用AsyncDisplayKit包装嵌套的ASStackLayoutSpec,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51289032/