Monday, December 18, 2023
HomeiOS Developmentios - UIHostingController mistaken top animation

ios – UIHostingController mistaken top animation


In iOS 17, every time I modify the peak of a UIHostingController in a animation block, the basis SwiftUI.View ignores it:

class TestAnimationController: UIViewController {

    var heightConstraint: NSLayoutConstraint!

    // a fundamental set off
    override func touchesEnded(_ touches: Set<UITouch>, with occasion: UIEvent?) {
        tremendous.touchesEnded(touches, with: occasion)
        heightConstraint.fixed = heightConstraint.fixed == 300 ? 100 : 300
        UIView.animate(withDuration: 1.0) {
            self.view.layoutIfNeeded()
        }
    }

    override func viewDidLoad() {
        tremendous.viewDidLoad()
        let content material = UIHostingController(rootView: Shade.crimson)
        addChild(content material)
        view.addSubview(content material.view)
        content material.view.translatesAutoresizingMaskIntoConstraints = false
        heightConstraint = contentView.heightAnchor.constraint(equalToConstant: 100)
        heightConstraint.isActive = true
        contentView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
        contentView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        contentView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
        content material.didMove(toParent: self)
    }
}

The result’s horrible:

iOS 17

It was not the case in iOS 14.5:

iOS 14

Does somebody have a workaround?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments