Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I add views to a
TZStackView
(which should be basically the same as a
UIStackView
, but with a fallback for older versions) like this:
stackView.addArrangedSubview(subview)
the stackView
and the subview
are of dynamic size (auto-layout) and resize themselves. However, this happens with an animation (I think due to addArrangedSubview
, it does not happen if I add it as subview and set constraints). Is there a way to deactivate the animations?
–
–
Disabling animations while adding arranged views to a UIStackView does not work properly in iOS 9.
The solution is to perform the addition separately from the layout:
// Add all views first.
for view in views {
stackView.addArrangedSubview(view)
// Now force the layout in one hit, sans animation.
UIView.performWithoutAnimation {
stackView.setNeedsLayout()
stackView.layoutIfNeeded()
Tested on iOS 9.3, Xcode 8.3.2.
Not tested on iOS 10 or 11 yet.
–
–
UIView performWithoutAnimation: will execute its block argument without animation:
UIView.performWithoutAnimation {
stackView.addArrangedSubview(subview)
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.