25

I have a project that was working just fine with XCode 5 and iOS 7, but when I recently downloaded XCode 6, I noticed some weird behavior with autolayout.

I have a storyboard with a view that just has a UIImageView and two UILabels. This view gets loaded using a UiPageViewController. The UIImageView is centered horizontally and vertically in the view and there are constraints specifying the distance of the two labels from the image view. When there is a case when the storyboard and autolayout values conflict (for example, in the storyboard, one label is 20 pixels above the image view but the autolayout says it should be 40 pixels above), it used to be that the autolayout value was successfully applied before the view loaded. Thus, when the view gets shown for the first time, everything is in the right place.

Now with iOS 8 / XCode 6, I'm seeing that the view loads and then things jump to their final autolayout position. This jump is noticeable to the end user both in the simulator and on a real device, and it's really annoying. Is there a way to go back to the old behavior? As far as I'm aware, no code has changed to cause this issue.

wuc
  • 251
  • 3
  • 3
  • 2
    See my answer here: http://stackoverflow.com/a/26290775/1342565 – dfickling Oct 10 '14 at 01:58
  • Have the same issue, very annoying. It's applied not only to view controllers, but also for collection and table view cells. – Mikhail Oct 21 '14 at 19:07
  • this is duplicate of this issue http://stackoverflow.com/questions/25791183/ios-8-uipageviewcontroller-applying-constraints-after-transitions – kraag22 Mar 19 '15 at 14:35

3 Answers3

9

Where is your code that is making changes to your constraints?

If you're keeping it in viewWillAppear: you will have that problem. I found that viewDidLayoutSubviews works well for iOS8 but not always for iOS7 backwards.

Eventually, if you cant use viewDidLayoutSubviews, what I'd suggest is hide the container view in viewDidLoad and unhide it in viewWillAppear, only after the constraints have been applied. It gets you a small extra delay when loading the screen but the constraints change gets transparent to the user.

Marcelo Ribeiro
  • 1,718
  • 1
  • 13
  • 27
  • 3
    That's the weird thing--I'm not changing the constraints at all. They're all specified at compile time in the storyboard. Let me try hiding the view and then unhiding it--that sounds like it should work. – wuc Sep 19 '14 at 02:14
  • 3
    In the end, I just ended up hiding all of the elements in the view in viewDidLoad and then unhiding them in viewDidAppear. This seems to be a bug with UIPageViewController in iOS 8, as autolayout doesn't have this glitch in previous versions of iOS. – wuc Sep 19 '14 at 21:51
  • @wuc - how did you hide all of the elements and then unhide them? I'm having trouble thinking how that would work. – CommaToast Apr 20 '15 at 18:06
0

I had a similar issue and put items into a container view in preparation for hiding and then showing them as suggested in the other answer.

I didn't love that as a solution and ended up not having to do it.

Simply putting them in a container view that was pegged to the controller's view stopped the issue from happening.

mwright
  • 4,099
  • 7
  • 30
  • 40
0

For me it was an issue with the tab bar in my project. I didn't need it in that view and I hid it on push. So when the view got pushed onto the stack the bar was hidden and the constraints adjusted accordingly. So I just put the tab bar back in.

dcotter
  • 312
  • 6
  • 22