0

我想让单元格全宽ASCollectionNode,但我会CellNodes按内容调整大小。我已经实施了layoutSpecThatFits:

看图片

4

1 回答 1

0

我实现这一点的方法是在 ASTaticLayoutSpec 中添加具有全宽的额外节点。

在标题中:

@property (strong, nonatomic) ASDisplayNode *stretchNode;

在初始化

_stretchNode = [ASDisplayNode new]; [self addSubnode:_stretchNode];

layoutSpecThatFits:

- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
    _stretchNode.sizeRange = ASRelativeSizeRangeMakeWithExactCGSize(CGSizeMake(constrainedSize.max.width, 0.5f));

    NSArray *children = @[];

    ASStackLayoutSpec *mainStackLayoutSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStart children:children];
    ASStaticLayoutSpec *mainStaticLayoutSpec = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[mainInsetsLayoutSpec, _stretchNode]];

    return mainStaticLayoutSpec;
}

这里重要的部分是将您的布局和stretchNode 包装在ASTaticLayoutSpec 中。您可以将 StackLayout 替换为您想要的任何内容。

于 2016-05-31T08:31:04.927 回答