2

I'm using DMPagerViewController, but I tried used other ones, and they all appear to have similar behaviors.

I set up a git to try to understand what's happening: https://github.com/LucasCoelho/DMPager-Example

Basically I added twice, from the storyboard, a ViewController to the DMPagerViewController and set it as the rootViewController of a UINavigationController who is the window's rootViewController

The view controller contains a UIButton that pushes another instance of the same ViewController and a label who is set at viewWillAppear(_:) who displays view.frame.size.height

What I'm struggling with is that the height of the first view shown doesn't match with the subsequent views pushed.

Can anyone please tell me why?

Here's some code if you don't want to download it on github:

App Delegate's application:didFinishLaunchingWithOptions

pagerController = DMPagerViewController(viewControllers:[firstViewController, secondViewController])

let navController = UINavigationController(rootViewController: pagerController)
navController.navigationBar.translucent = false

window?.rootViewController = navController
Victor Sigler
  • 23,243
  • 14
  • 88
  • 105
Lucas
  • 6,675
  • 3
  • 25
  • 43
  • So, Do you want to match all view the frame height? – Yuyutsu Apr 30 '15 at 08:26
  • What I really want is the views to look the same and not to use a translucent UINavigationBar – Lucas Apr 30 '15 at 08:42
  • Embedded `UINavigationController`. Relationship "root view controller" to View Controller. it works for you I think your problem is solved – Yuyutsu Apr 30 '15 at 08:55
  • Sorry, I don't think I understood. Are you suggesting I don't use pagerController? – Lucas Apr 30 '15 at 09:08
  • click on `ViewController` then `Menu=>Editor=>Embed In=> Navigation Controller` [1]: http://i.stack.imgur.com/uZM6x.png – Yuyutsu Apr 30 '15 at 09:10
  • @Yuyutsu nothing changes when I do that – Lucas Apr 30 '15 at 09:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76619/discussion-between-lucas-and-yuyutsu). – Lucas Apr 30 '15 at 09:25

2 Answers2

0

It is because of the navigation bar.

DMPagerViewController has it's own custom navigation bar so it doesn't seem to consider the navigation bar of the UINavigationController.

If you use the Debug View Hierarchy mode in Xcode you'll see that the view it's not shown completely on screen.

If you set navController.navigationBar.translucent = true, you'll see the you're label will report the same size all the time.

Victor Sigler
  • 23,243
  • 14
  • 88
  • 105
pteofil
  • 4,133
  • 17
  • 27
  • navController.navigationBar.translucent = true you mean? – Lucas Apr 30 '15 at 08:06
  • We're on the right track. But even with that modification, why is the button placed differently on the screen? – Lucas Apr 30 '15 at 08:15
  • If you scroll the view up, you'll see that you can get it to have the same position as the one pushed. It seems as the DMPagerViewController doesn't play nice with UINavigationController. – pteofil Apr 30 '15 at 08:20
0

You have this bug because the subviews of DMPagerViewController do not fit to the parent view, because, there are no contraints and no autoresizing mask to update them, that is why the bug appear only in DMPagerViewController and not in ViewController. So to fix that, just uncomment this line in the initializer of DMPagerViewController :

//   _scrollView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

Now, the bug is fixed but the content height of scrollView is larger than view height.

Explanation :

We get the real frame of the view only when this method is called viewDidLayoutSubviews, and because we calculate the content size of the scrollView before that, so we get a wrong value. To fix that, we should add some code in viewDidLayoutSubviews or in viewDidAppear (this two methods called when autolayout is completed.), I prefer viewDidAppear because viewDidLayoutSubviews is called multiple times.

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    [self adjustControllerLayout];
    [self adjustPagerNavigationBarOnScroll];
}

You can find more informations here

Hope that helps

HamzaGhazouani
  • 6,464
  • 6
  • 33
  • 40