Aleksander
Aleksander

Reputation: 2815

AutoLayout updates positions automatically when presented

I have a UIPageViewController with multiple pages, and every time I scroll to a new page the content is slightly under the top layout guide. But when the view is finally displayed to the user/ settled in the middle, it moves down as it should've been.

I'm using autolayout in storyboards to lay out my content, and I've set the Top Space to Top Layout Guide: 5p.

This only seems to happen when using a UIPageViewController - I don't have this problem with AutoLayout normally, and this is not the first time I've had it with the pageview controller.

Does anyone know what I can do so the view is correctly placed under the top layout guide before it's presented to the user, so it doesn't jump as soon as it's presented?

Upvotes: 2

Views: 182

Answers (2)

kai Taylor
kai Taylor

Reputation: 795

For others that may come across this question. The best answer I could find relating to this is in this SO response,

[question]iOS 8 UIPageViewController Applying Constraints After Transitions

The issue is caused because in iOS 8 the default auto layout behaviour is to align to margins, where in previous iOS versions it was to the views edges. The margins are not calculated till after the pageviewcontroller finishes animating, which is what causes the jumping around of the view.

It can however be fixed by unselecting the align to margin for each constraint. Hope this helps anybody.

Upvotes: 0

Aleksander
Aleksander

Reputation: 2815

Turns out this is a problem with iOS8, and that it can be solved by using Top Space to View instead of Top Layout guide.

I hope this is of help to anyone else having the same issue.

Upvotes: 1

Related Questions