1

i've created a view with an header and a container... inside the container there is a page view controller

the header resize based on the container, throught an iboutlet constraint

if there is a table view as page in the container then the header resize based on the scroll offset, without animation

if i scroll between pages i want the header to be resized, so i've created a delegate method that listen the end of the scroll animation and then resize the header

but if i animate this resizing with this code

UIView.animate(withDuration: 0.5,animations: {
    self.imageViewHeightConstraint.constant = ct
    self.view.layoutIfNeeded()
 }, completion: {
     _ in
     if let handler = handler {
         handler()
     }
})

then the pages are "reloaded" after the resizing it's complete

this is a video of the animation ( the red background is the background of the page view controller that i've edited for debug reason)

Video of the Wrong Animation

1 Answers1

0

Please set constant outside the animation block like this,

self.imageViewHeightConstraint.constant = ct

UIView.animate(withDuration: 0.5,animations: {
    self.view.layoutIfNeeded()
}, completion: {_ in
    UIView.commitAnimations()
    if let handler = handler {
        handler()
    }
})
Patel Jigar
  • 2,141
  • 1
  • 23
  • 30
  • please check the constant value, i guess this sould work – Patel Jigar Mar 01 '17 at 13:05
  • in what way? it's a normal cgfloat, that change based on my algorithym – Giorgio Romano Mar 01 '17 at 13:18
  • check "ct" value it will change as per its value so it can be issue of your algorithm, you can check it by printing "ct" – Patel Jigar Mar 01 '17 at 13:27
  • and for view animation with constraint you have to set constant value outside the block – Patel Jigar Mar 01 '17 at 13:29
  • i had seen your video, what you have to do is stop animation then perform swipe, and when you come at the next view dont set animation just set constant value directly – Patel Jigar Mar 01 '17 at 13:32
  • the step are those i swipe the page view controller the delegate method of the page controller, didFinishAnimating, it's performed and there i call a method constraintDelegate ( which is my root view controller ) to set the new constraint height inside that method it's the bit of code wrote before so i call the animation after the swipe has endend – Giorgio Romano Mar 01 '17 at 13:53
  • Add **UIView.commitAnimations()** before you call handler check the code – Patel Jigar Mar 02 '17 at 04:26