ASCellNode 内部水平布局显示错误
Wrong display of horizontal layout inside ASCellNode
我使用 AsyncDisplayKit 编写了这段代码:
override open func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let horizonTitleDate = ASStackLayoutSpec(direction: .horizontal, spacing: 5, justifyContent: .start, alignItems: ASStackLayoutAlignItems.start, children: [title,space, datetime])
let verticalMess = ASStackLayoutSpec(direction: .vertical, spacing: 5, justifyContent: .start, alignItems: ASStackLayoutAlignItems.start, children: [horizonTitleDate, desc])
let horizonMess = ASStackLayoutSpec(direction: .horizontal, spacing: 5, justifyContent: .start, alignItems: ASStackLayoutAlignItems.start, children: [avatar, verticalMess])
//desc.style.width = ASDimensionMake(constrainedSize.max.width - 100)
desc.style.alignSelf = .stretch
desc.style.flexGrow = 1.0
desc.style.flexShrink = 1.0
verticalMess.style.alignSelf = .stretch
verticalMess.style.flexGrow = 1.0
horizonTitleDate.style.alignSelf = .stretch
let insets = UIEdgeInsetsMake(5, 5, 5, 5)
return ASInsetLayoutSpec(insets: insets, child: horizonMess)
}
我得到这个:
如你所见,黄色的TextNode,比cellNode大,而且没有变成2行,纵向模式下是这样的:
如果我只绘制垂直布局而没有头像,我获得正确的视图:
怎么了?谢谢!
我没有看到 flexShrink
verticalMess
。尝试只添加这一行:
verticalMess.style.flexShrink = 1.0
我使用 AsyncDisplayKit 编写了这段代码:
override open func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let horizonTitleDate = ASStackLayoutSpec(direction: .horizontal, spacing: 5, justifyContent: .start, alignItems: ASStackLayoutAlignItems.start, children: [title,space, datetime])
let verticalMess = ASStackLayoutSpec(direction: .vertical, spacing: 5, justifyContent: .start, alignItems: ASStackLayoutAlignItems.start, children: [horizonTitleDate, desc])
let horizonMess = ASStackLayoutSpec(direction: .horizontal, spacing: 5, justifyContent: .start, alignItems: ASStackLayoutAlignItems.start, children: [avatar, verticalMess])
//desc.style.width = ASDimensionMake(constrainedSize.max.width - 100)
desc.style.alignSelf = .stretch
desc.style.flexGrow = 1.0
desc.style.flexShrink = 1.0
verticalMess.style.alignSelf = .stretch
verticalMess.style.flexGrow = 1.0
horizonTitleDate.style.alignSelf = .stretch
let insets = UIEdgeInsetsMake(5, 5, 5, 5)
return ASInsetLayoutSpec(insets: insets, child: horizonMess)
}
我得到这个:
如你所见,黄色的TextNode,比cellNode大,而且没有变成2行,纵向模式下是这样的:
如果我只绘制垂直布局而没有头像,我获得正确的视图:
怎么了?谢谢!
我没有看到 flexShrink
verticalMess
。尝试只添加这一行:
verticalMess.style.flexShrink = 1.0