UIView frames reset when using autolayout

后端 未结 3 2171
轻奢々
轻奢々 2021-02-15 16:23

I\'m facing an issue. I\'m working on an app and I\'m using storyboard with Autolayout enabled. Now on one of my UIViewControllers

相关标签:
3条回答
  • 2021-02-15 16:46

    For all the views that you are animating write the following code in viewDidLoad

    myViewToAnimate.translatesAutoresizingMaskIntoConstraints = YES;
    

    Hope this helps

    0 讨论(0)
  • 2021-02-15 17:03

    The reason is Autolayout will update the views to their original position. The Autolayout system will periodically set the position and size of every view in your view hierarchy based on the layout constraints.

    0 讨论(0)
  • 2021-02-15 17:07

    Add this:

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        VIEWTOFIX.setTranslatesAutoresizingMaskIntoConstraints(true)
    }
    

    Putting it in viewDidLayoutSubviews instead of viewDidLoad got rid of the layout constraint errors for me.

    0 讨论(0)
提交回复
热议问题