我对Texture/AsyncDisplayKit
非常陌生。我能够用这个简单的代码重现这个问题。
我基本上想在ASCellNode
的右下角显示一个10 x10的正方形。我是通过一个ASDisplayNode
来实现的,它被设置为ASCornerLayoutSpec
的角。我已经将ASDisplayNode
的style.preferredSize
设置为CGSize(width: 10, height: 10)
。
由于某种原因,宽度不起作用,显示为屏幕宽度的50%:
代码:
import UIKit
import AsyncDisplayKit
class ViewController: ASDKViewController<ASDisplayNode>, ASTableDataSource {
var tableNode = ASTableNode()
override init() {
super.init(node: tableNode)
node.automaticallyRelayoutOnSafeAreaChanges = true
node.automaticallyManagesSubnodes = true
tableNode.dataSource = self
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func tableNode(_ tableNode: ASTableNode, numberOfRowsInSection section: Int) -> Int {
return 100
}
func tableNode(_ tableNode: ASTableNode, nodeBlockForRowAt indexPath: IndexPath) -> ASCellNodeBlock {
let cellNodeBlock = { () -> ASCellNode in
let cellNode = CellNode()
return cellNode
}
return cellNodeBlock
}
}
class CellNode: ASCellNode {
fileprivate let titleNode = ASTextNode()
fileprivate let savedIconNode = ASDisplayNode()
override init() {
super.init()
self.automaticallyManagesSubnodes = true
titleNode.attributedText = NSAttributedString(string: "This is my title!", attributes: [.font : UIFont.systemFont(ofSize: 20),.foregroundColor:UIColor.white])
savedIconNode.isLayerBacked = true
savedIconNode.backgroundColor = .green
savedIconNode.style.preferredSize = CGSize(width: 10, height: 10)
}
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let paddingToUse = 15.0;
let contentView = ASInsetLayoutSpec(insets: UIEdgeInsets(top: paddingToUse, left: paddingToUse, bottom: paddingToUse, right: paddingToUse), child: ASStackLayoutSpec(direction: .horizontal, spacing: 5, justifyContent: .spaceBetween, alignItems: .notSet, children: [titleNode]))
let contentViewAndSaveTriangle = ASCornerLayoutSpec(child: contentView, corner: savedIconNode, location: .bottomRight)
return contentViewAndSaveTriangle
}
}
1条答案
按热度按时间jdgnovmf1#
您可以通过在
ASCornerLayoutSpec
构造函数中为角节点提供所需的宽度和高度来修复此问题,如下所示:ASCornerLayoutSpec
不考虑savedIconNode
的preferredSize
,相反,角节点的大小由子节点的大小决定。