Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content pushed down in a UIPageViewController with UINavigationController

UPDATE 2

I've been running and testing my app in the iOS Simulator using a 4-inch device. If I run using a 3.5-inch device the label doesn't jump. In my .xib, under Simulated Metrics, I have it set as Retina 4-inch Full Screen. Any idea why I'm only seeing this problem on a 4-inch device?

UPDATE 1

In IB, if I choose "Navigation Bar" in Simulated Metrics, my label still jumps. The only way I can get my label to render correctly on the first screen is to not set a navigation controller as my window's root view controller.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

My window's rootViewController is being set to a UINavigationController whose rootViewController has a UIPageViewController embedded.

When my app loads, the initial view is presented with it's content pushed down a bit, roughly the same size as a navigation bar. When I scroll the pageViewController, the content jumps up to where it was placed in the nib, and all other viewControllers loaded by the pageViewController are fine.

uipageviewcontroller with navigationcontroller

In my appDelegate:

self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[ContainerViewController new]]; 

In ContainerViewController:

- (void)viewDidLoad {      [super viewDidLoad];      self.pvc = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll                                                navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal                                                              options:nil];     self.pvc.dataSource = self;     self.pvc.delegate = self;     DetailViewController *detail = [DetailViewController new];     [self.pvc setViewControllers:@[detail]                        direction:UIPageViewControllerNavigationDirectionForward                         animated:false                       completion:nil];      [self addChildViewController:self.pvc];     [self.view addSubview:self.pvc.view];     [self.pvc didMoveToParentViewController:self]; } 
like image 411
djibouti33 Avatar asked Aug 13 '13 06:08

djibouti33


People also ask

How UINavigationController works?

A navigation controller is a container view that can manage the navigation of hierarchical contents. The navigation controller manages the current displaying screen using the navigation stack. Navigation stack can have “n” numbers of view controllers.

Is UINavigationController a UIViewController?

A UINavigationController does a lot of this tedious work for you. As mentioned, it contains a stack of UIViewControllers. It will create a navigation bar at the top that will allow you to easily go back up the hierarchy of view controllers.

Which method is used to display the view controller in the UINavigationController container in swift?

You add and remove view controllers from the stack using segues or using the methods of this class. The user can also remove the topmost view controller using the back button in the navigation bar or using a left-edge swipe gesture.

What is Pushviewcontroller?

Pushing a view controller causes its view to be embedded in the navigation interface. If the animated parameter is true , the view is animated into position; otherwise, the view is simply displayed in its final location.


1 Answers

So I'm adding another answer after further development and I finally think I figured out what's going on. Seems as though in iOS7, UIPageViewController has its own UIScrollView. Because of this, you have to set automaticallyAdjustsScrollViewInsets to false. Here's my viewDidLoad now:

- (void)viewDidLoad {     [super viewDidLoad];      self.automaticallyAdjustsScrollViewInsets = false;      DetailViewController *detail = [[DetailViewController alloc] init];     [self setViewControllers:@[detail]                    direction:UIPageViewControllerNavigationDirectionForward                     animated:false                   completion:nil]; } 

No need to put anything in viewWillLayoutSubviews (as one of my previous answers suggested).

like image 68
djibouti33 Avatar answered Oct 05 '22 08:10

djibouti33