Paul T.
Paul T.

Reputation: 5038

Strange constraint behaviour in UIPageViewController

In storyboard I have UINavigationController without navigation bar and with root view controller UIPageViewController that has 2 children: LoginVC and ChoosePlaceVC.

MainPageVC is a simple subclass of UIPageViewController where I just set

[self setViewControllers:@[loginVC] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

In Login ViewController I set constraint to top for logo image to 0 (distance of the logo to the top of the screen is 0). But when I see it the first time the distance from status bar is 20, and only when I go to next VC in UIPageViewController (weakSelf is a weak reference to custom UIPageViewController):

[weakSelf setViewControllers:@[choosePlaceVC] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {

        }];

and then go back to login VC:

[weakSelf setViewControllers:@[loginVC] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {

        }];

the distance from logo to status bar becomes 0. When I repeat moving to next VC and going back, the distance stays = 0 (and that's the right distance)

Why does it appear the first time with the distance = 20 ?

Upvotes: 0

Views: 243

Answers (1)

Paul T.
Paul T.

Reputation: 5038

After a long investigation I figured it out:

In Storyboard in Attributes inspector of UIPageViewController in Extend Edges I unchecked in the checkboxes Under Top Bars and Under Bottom Bars.

And now the strange behaviour of constraints in fixed (and I noticed that in this case I anyway have the offset from the top of view = 20 px, but in always constant. But if add the subview of main view with the size like the main view, and if I add all the elements to this subview, the distance to top = 0 px).

Upvotes: 1

Related Questions