AutoLayout weird behaviour iOS

122 views Asked by At

When I push to a UIViewControllerB and then pop back to UIViewControllerA entire view of UIViewControllerA is about 20 px higher then it should be and in a moment (I guess after viewDidAppear) it moves to its normal position. I do not manipulate constrains or UINavigationBar settings in any way while this. I do have all elements of UIViewControllerA top space to top layout guide. What might cause this? I've worked with storyboard a few and have never faced something like this.

3

There are 3 answers

0
JuicyFruit On BEST ANSWER

This was somehow caused by removing subview, I've added to cover screen while loading data: after removing this subview, constrains where changed (this only happened on this UIViewController, other UIViewControllers with this subview are fine). I've fixed it by doing this:

self.stopLoading() //removes subview
self.view.layoutIfNeeded()
0
AudioBubble On

Try adding view.layoutIfNeeded() in your viewDidLoad or viewDidAppear.

0
Will Boland On

The most recent XCode adds some new behaviors. Try setting the constraints of UIViewControllerA to have the top one be flush with the bottom of the UINavigationBar.