2016-02-17 38 views
2

我的ASTextNod通常采取3行,但我从第二行中trancate它。 Resultat:我的ASTextNod显示2行和3点的trancate,但他的身高是3行的高度,而不是2.SizeToFit AsyncDisplayKit

我看起来很类似于ASTToxtNode的sizeToFit。

回答

3

我花了一段时间熟悉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 
    } 
}