0

I don't know what is going on but this will happened a lot of time to me. I used UIStackView for arranging the view and animation but when I hide the control in UIStackView there will be some sort of weird animation is there. Here I attached video and code.

UIView.animate(withDuration: 0.5, animations: {
    self.viewCollectionSpecies.isHidden = true
})

enter image description here

Vukašin Manojlović
  • 3,717
  • 3
  • 19
  • 31
Chirag Shah
  • 3,034
  • 1
  • 30
  • 61

3 Answers3

1

Try

self.viewCollectionSpecies.alpha = 0
UIView.animate(withDuration: 0.5, animations: {
     self.viewCollectionSpecies.isHidden = true
     self.stackView.layoutIfNeeded()
})

Or

self.viewCollectionSpecies.isHidden = true
UIView.animate(withDuration: 0.5, animations: {
     self.stackView.layoutIfNeeded()
})
Vukašin Manojlović
  • 3,717
  • 3
  • 19
  • 31
Aakash
  • 2,239
  • 15
  • 23
1

Finally i got clue what is issue. There will be one height constraint which I need to forgot to remove after removing that constraint it work perfectly.

self.heightConstraint.constant = 0.0
            UIView.animate(withDuration: 0.5, animations: {
                self.viewCollectionSpecies.isHidden = true
                self.layoutIfNeeded()
            })
Chirag Shah
  • 3,034
  • 1
  • 30
  • 61
0

Try working with the alpha value:

func changeViewTo(newView: UIView, oldView: UIView) {
    newView.isHidden = false
    newView.alpha = 0
    UIView.animate(withDuration:0.4, animations: {
        oldView.alpha = 0
        newView.alpha = 1
    }) { (result: Bool) in
        oldView.isHidden = true
    }
    layoutIfNeeded()
    self.stackView.layoutIfNeeded()
}
Noodledew
  • 509
  • 4
  • 19