I have an UIStackView build in interface builder which changes it's axis property from vertical to horizontal when it's superview rotates from portrait to landscape. The issue is that this results in an animation of it's two arranged subviews, where one of those views overlaps the other view while transitioning to the new position.
In my case I would like to remove only that particular animation and force the view to it's end position right away.
I have tried to remove all animation on from the stackview layer in my VC:
public override func willTransition(to newCollection: UITraitCollection,
with coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animate(alongsideTransition: {
_ in
// The first subview is `UIStackView`
self.view.subviews[0].layer.removeAllAnimations()
})
super.willTransition(to: newCollection, with: coordinator)
}
And I observed the animation keys when the axis property is changed, because that seems to happen somewhere during the transition (set automatically by interface builder). Unfortunately I had no luck with it, because the layer returns nil for animationKeys on the stackview and its subviews/arrangedSubviews.
class StackView : UIStackView {
override var axis: UILayoutConstraintAxis {
didSet { /* here */ }
}
}