How do I animate constraint changes?

后端 未结 12 1875
野的像风
野的像风 2020-11-21 23:22

I\'m updating an old app with an AdBannerView and when there is no ad, it slides off screen. When there is an ad it slides on the screen. Basic stuff.

O

12条回答
  •  清歌不尽
    2020-11-21 23:50

    Working Solution 100% Swift 3.1

    i have read all the answers and want to share the code and hierarchy of lines which i have used in all my applications to animate them correctly, Some solutions here are not working, you should check them on slower devices e.g iPhone 5 at this moment.

    self.view.layoutIfNeeded() // Force lays of all subviews on root view
    UIView.animate(withDuration: 0.5) { [weak self] in // allowing to ARC to deallocate it properly
           self?.tbConstraint.constant = 158 // my constraint constant change
           self?.view.layoutIfNeeded() // Force lays of all subviews on root view again.
    }
    

提交回复
热议问题