The presence of UIToolbar, affecting the layout of the controller view

I have a subclass of UIPageViewController that displays 1 view controller at a time. The displayed view controller has a scrollview. This allows the user to scroll left / right to go to a new page, or up to view content larger than the height of the screen. A subclass of UIPageViewController is built into the UINavigationController, and the navBar toolbar is visible.

This subclass of UIPageViewController can be obtained from two different parts of my application.

In my first viewController, the toolbar is hidden . Clicking on an element in this controller view loads the UIPageViewController and everything looks fine.

In my second viewController, the toolbar is visible . Clicking on an item in this view controller loads the UIPageViewController, but my content (viewViewController viewController) is a bit off the navigation bar. As soon as I interact with scrollView, the view automatically adjusts itself to sit right below the navigation bar.

I am running this on iOS7, but I'm not sure if this has anything to do.

Why does my view controller load differently when it comes from two different parts of the application: one with a toolbar, one hidden with it?

+4
source share
2 answers

If your application works well on iOS6 but not iOS7, try setting NO to the UIPAPViewController (UIPVC) property automaticallyAdjustsScrollViewInsets .

UIPVC seems to have scrollview inside. In iOS7, the UIViewController property automaticallyAdjustsScrollViewInsets is set to YES by default. I think this will not work if it is built into the UINavigationController.

In my case, I created a custom UIPVC and put the following code in the [viewDidLoad] method.

self.automaticallyAdjustsScrollViewInsets = NO; 
+2
source

Finally, I was able to correctly align the built-in UIPageViewController in the NavController, which itself is inside the TabBarcontroller. I did this by programmatically creating a pageViewController inside a dummy “rootviewcontroller”, following the example specified in the standard Xcode “New Project” called “Page Based Application”.

In my case, the following layout layout generates an error: TabBarController -> NavController -> UIPageViewController (scroll-horizontal) -> ContentViewController

I changed the layout of the layout: TabBarController -> NavController -> CustomRootViewController

CustomRootViewController creates an instance of UIPageViewController and saves it as a member property. CustomRootViewController becomes a DataSource and Delegate for its PageViewController. Follow the standard Xcode “New Project” called “Page-based Application” for an example of how to configure RootViewController.

Unfortunately, this whole problem is caused by an error in the Storyboard when you use the "UIPageViewController" with drag and drop horizontally, built into navController (and / or tabbarcontroller). FYI. In the pageViewControllerWillAppear view, I tried to reset the frame on the ViewController page and the contentViewControllers each at (0,0) with the size corresponding to the device, and yet the initial viewController pageViewController view will always be reset by what appeared to be the height of the tabbarcontroller in which it was embedded. Here are a few notes for those who want to continue this question:

  • In viewDidLoad, you can set Frame from the initial pageViewController to offset the layout error. But then you may have to deal with various layout adjustments for different devices in different orientations, and this can be a headache along the way.

  • In Storyboard, setting the pageViewController transition style to "page freeze" fixes a layout problem. Therefore, I am sure that the layout problem is in the scroll page that is set when the instance is created. Creating a Storyboard object will result in a layout error, but the software implementation in my CustomRootViewController will be error free.

+1
source

Source: https://habr.com/ru/post/1501914/


All Articles