到目前为止,我已经使用 AsyncDisplayKit 做了很多工作,我真的很满意。不幸的是,现在我遇到了障碍。
我无法让 ASButtonNode 具有最小高度(如果这很重要,则在 ASCellNode 中)。
class SmallButtonCellNode: ASCellNode {
let normalSmallButton = ASButtonNode()
let selectedSmallButton = ASButtonNode()
init() {
super.init()
self.backgroundColor = UIColor.lightGrayColor()
// .. button title and background configuration here ..
let buttonSizeRange =
ASRelativeSizeRangeMake(
ASRelativeSizeMake(
ASRelativeDimensionMakeWithPercent(0),
ASRelativeDimensionMakeWithPoints(35.0)
),
ASRelativeSizeMake(
ASRelativeDimensionMakeWithPercent(1),
ASRelativeDimensionMakeWithPoints(35.0)
)
);
self.normalSmallButton.preferredFrameSize = CGSize(width: 111.0, height: 35.0)
self.normalSmallButton.flexGrow = true
self.normalSmallButton.sizeRange = buttonSizeRange
self.addSubnode(self.normalSmallButton)
self.selectedSmallButton.preferredFrameSize = CGSize(width: 111.0, height: 35.0)
self.selectedSmallButton.flexGrow = true
self.selectedSmallButton.sizeRange = buttonSizeRange
self.addSubnode(self.selectedSmallButton)
}
// MARK: - Layout
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec {
let spec =
ASStackLayoutSpec(
direction: .Horizontal,
spacing: 20.0,
justifyContent: .SpaceAround,
alignItems: .Center,
children: [self.normalSmallButton, self.selectedSmallButton]
)
return
ASInsetLayoutSpec(
insets: UIEdgeInsets(top: 20.0, left: 20.0, bottom: 20.0, right: 20.0),
child: spec
)
}
}
结果是(尽管 constrainedSize 的最大高度为 100.0):
ASButtonNodes 仅适合文本高度。
我试过了:
- 删除首选帧大小(无效)
- 从更改
.Center
为.Stretch
(按钮与单元格一样高 - 插图) - flexGrow = true 在各个地方
我知道我可以使用将单元格高度从 100 更改为 75 .Stretch
,然后按钮将自动最终变为 35 pts 高,但这不是我想要的(因为“按钮为 35 pts 高”的布局逻辑实际上是集合视图委托的一部分..)
请帮忙 :)