2

UIStackView hide show animation is very different between ios versions. Here is a basic setup. I have a UIStackView with three arranged subviews inside it. And UIScrollView contains UIStcakView. I use auto layout. The stack view code is this:

let stack = UIStackView(arrangedSubviews: [view1, view2, view3])
stack.translatesAutoresizingMaskIntoConstraints = false

stack.axis = .vertical
stack.distribution = .fill
stack.alignment = .fill

The code that makes animation is this:

isHidden.toggle()

UIView.animate(withDuration: 2) {
    self.view3.isHidden = self.isHidden
}

When this runs on ios 10 simulator the animation is correct.

ios 10 animation

However in ios 13 the animation is not correct.

ios 13

So is there a way to make this animation just like on ios10? Or should I use UITableView instead of UIStackView?

mustafa
  • 15,254
  • 10
  • 48
  • 57

1 Answers1

2

It looks like you forgot to decrease priority for view3 height constraint.

UIStackView hides it's subviews by constraining their height to 0, so if you have other constraints for view height, they will conflict with the stack view.

Konstantin Oznobihin
  • 5,234
  • 24
  • 31
  • Indeed this is the case. By default every nslayoutconstraint has required priority when created. This is same both for ios 10 and 13. But It seems the way UIStackView handles constraint priority has changed in ios 12. Setting prioriy to defaultLow for height constraint solved the problem. Thanks. – mustafa Nov 08 '19 at 10:58