我的ASTextNod通常需要3行代码,但我从第二行代码中删除了它。结果:我的ASTextNod显示了2条线和3个点,但他的高度是3条线的高度,而不是2。
我正在寻找类似于ASTextNode上的sizeToFit的东西。
发布于 2016-02-17 23:29:19
我花了一段时间来熟悉ASDisplayKit中的布局,而且在线资源非常有限。您需要使用insetSpecs。但是,如果你能提供更多关于如何以及在哪里展示它的细节,那就更容易了。
下面是一个ASCellNode的例子,它的文本具有动态的高度和宽度,宽度小于屏幕尺寸,高度最大为200磅。
class MyNode: ASCellNode {
var myText: ASTextNode
init() {
myText = ASTextNode()
addSubnode(myText)
}
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec {
let cellWidth = UIScreen.mainScreen().bounds.size.width
myText.sizeRange = ASRelativeSizeRangeMake(
ASRelativeSize(
width: ASRelativeDimensionMakeWithPercent(0),
height: ASRelativeDimensionMakeWithPoints(0)),
ASRelativeSize(
width: ASRelativeDimensionMakeWithPercent(cellWidth),
height: ASRelativeDimensionMakeWithPoints(200)))
let insetSpecs = ASInsetLayoutSpec(
insets: UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8),
child: myText)
return insetSpecs
}
}https://stackoverflow.com/questions/35458548
复制相似问题