The child view controller shifts down

I have a TutorialsViewController with software to view a PageViewController, like:

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // Create page view controller self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"TutorialsPageViewController"]; self.pageViewController.dataSource = self; TutorialsContentViewController *startingViewController = [self viewControllerAtIndex:0]; NSArray *viewControllers = @[startingViewController]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; [self addChildViewController:self.pageViewController]; [self.view addSubview:self.pageViewController.view]; [self.pageViewController didMoveToParentViewController:self]; } 

And I add the TutorialsContentViewController to the PageViewController using delegate methods:

 - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { NSUInteger index = ((TutorialsContentViewController*) viewController).pageIndex; if ((index == 0) || (index == NSNotFound)) { return nil; } index--; return [self viewControllerAtIndex:index]; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { NSUInteger index = ((TutorialsContentViewController*) viewController).pageIndex; if (index == NSNotFound) { return nil; } index++; if (index == [self.tutorialsArray count]) { return nil; } return [self viewControllerAtIndex:index]; } - (TutorialsContentViewController *)viewControllerAtIndex:(NSUInteger)index { if (([self.tutorialsArray count] == 0) || (index >= [self.tutorialsArray count])) { return nil; } // Create a new view controller and pass suitable data. TutorialsContentViewController *tutorialsContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"TutorialsContentViewController"]; tutorialsContentViewController.imageName = [self.tutorialsArray objectAtIndex:index]; tutorialsContentViewController.pageIndex = index; return tutorialsContentViewController; } 

Now, when I run this in the simulator, I see that everything is working fine, so the next child view controller is above the status bar, and it moves down as it scrolls.

I tried self.automaticallyAdjustsScrollViewInsets = false in the parental control controller, but the child view is still reset. The child view controller has an ImageView, which has start, end, upper and lower limits set to 0 initially (this causes a shift).

When I center the image horizontally and vertically and give it a fixed height and width, it works fine. But I want the image to completely populate the child view controller.

How to solve this view bias problem? Please, help.

Thanks.

+7
ios objective-c autolayout uipageviewcontroller
source share
2 answers

It seems I found a fix for it, it was due to the auto layout limitations that I installed. The controller of my child view contains an image that completely fills it. Therefore, I give the following restrictions on the representation of the image:

  • Center horizontally in the container
  • Center vertically in the container
  • Equal widths (as container)
  • Equal heights (to container type)

This stops the bias / flicker problem of the view.

+4
source share

I solved this problem with this answer: iOS 8 UIPageViewController Applying constraints after transitions replacing all constraints in the PageViewController element with the top layout guide for viewing.

+3
source share

All Articles