How to give animation when I click button which toggle scope in Fscalendar with snapkit in iOS

168 Views Asked by At

I currently, I'd like to change FSCalendar's scope with animation using Snapkit.

The code below can replace scope with week and month. But the animation doesn't work.

    func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
            self.calendar.snp.updateConstraints { make in
                make.height.equalTo(bounds.height)
            }
        self.view.layoutIfNeeded()  
    }
1

There are 1 best solutions below

0
DonMag On

Hard to say, without knowing your layout (is calendar a subview of a subview of a subview, for example?), but, in general, to animate constraints you want to "wrap" the .layoutIfNeeded() in an animation block.

Try this:

    self.calendar.snp.updateConstraints { make in
        make.height.equalTo(bounds.height)
    }
    UIView.animate(withDuration: 0.5, animations: {
        self.view.layoutIfNeeded()
        
    })