TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8.02k stars 1.29k forks source link

ASTextNode2 incorrect layout comparing to ASTextNode #1530

Open IvanChan opened 5 years ago

IvanChan commented 5 years ago

height calculated by ASTextNode2 is higher than ASTextNode, also not center layout in its rect

1559310521889

class ViewController: UIViewController, UIScrollViewDelegate {

    let text = "爱豆那些事"
    lazy var aStr = NSAttributedString(string: text, attributes: [.font:UIFont.systemFont(ofSize: 30), .foregroundColor:UIColor.white])

    lazy var textNode1:ASTextNode = {
        let node = ASTextNode()

        node.attributedText = aStr
        node.backgroundColor = UIColor.red

        let layzoutSize = node.calculateLayoutThatFits(ASSizeRangeMake(.zero, CGSize(width: 999, height: 999)))
        node.frame = CGRect(x: 50, y: 200, width: 300, height: layzoutSize.size.height)
        return node
    }()

    lazy var textNode2:ASTextNode2 = {
        let node = ASTextNode2()
        node.attributedText = aStr
        node.backgroundColor = UIColor.red

        let layzoutSize = node.calculateLayoutThatFits(ASSizeRangeMake(.zero, CGSize(width: 999, height: 999)))
        node.frame = CGRect(x: 50, y: 300, width: 300, height: layzoutSize.size.height)
        return node
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.view.addSubnode(textNode1)
        self.view.addSubnode(textNode2)
    }
}

AsdkDEMO.zip

IvanChan commented 5 years ago

ASButtonNode will have the same problem if using ASTextNode2