How do I animate constraint changes?

后端 未结 12 1672
野的像风
野的像风 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:37

    Working and just tested solution for Swift 3 with Xcode 8.3.3:

    self.view.layoutIfNeeded()
    self.calendarViewHeight.constant = 56.0
    
    UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseIn, animations: {
            self.view.layoutIfNeeded()
        }, completion: nil)
    

    Just keep in mind that self.calendarViewHeight is a constraint referred to a customView (CalendarView). I called the .layoutIfNeeded() on self.view and NOT on self.calendarView

    Hope this help.

提交回复
热议问题