我正在尝试将嵌套的ASStackLayoutSpec与AsyncDisplayKit一起使用

ios - 用AsyncDisplayKit包装嵌套的ASStackLayoutSpec-LMLPHP

所以我要创建一个带有头像的垂直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)
}

但是结果却不是我所期望的

ios - 用AsyncDisplayKit包装嵌套的ASStackLayoutSpec-LMLPHP

看起来文本会达到无穷大,无法正确换行。时间戳也可能在右侧之外。

我尝试了.alignItems.justifyContent的不同组合,但无法正常工作。

最佳答案

尝试以下属性:

contentStackSpec.style.flexShrik = 1
messageNode.style.flexShrik = 1
contentStackSpec.children = [headerStackSpec, messageNode]

关于ios - 用AsyncDisplayKit包装嵌套的ASStackLayoutSpec,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51289032/

10-11 06:16