0

I have a parent view controller with 2 views.On Top, I have View, that contains Page View Controller and on Bottom I have other view that shows different content.

Everything works well, except getting white space below first view ( Page View Controller) and above second view.

I have added following code for constraints,

let views:[String: Any] = ["pageView": pageViewController.view!]
articleContentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat:     "H:|-0-[pageView]-0-|",
                                                                     options: NSLayoutConstraint.FormatOptions(rawValue: 0),
                                                                     metrics: nil, views: views))

    articleContentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[pageView]-0-|",
                                                                     options: NSLayoutConstraint.FormatOptions(rawValue: 0),
                                                                     metrics: nil, views: views))

If I remove this code , My Page View Controller exceeds its view and occupy full screen. Any suggestionsenter image description here much appriaciated.

Jay Vyas
  • 2,674
  • 5
  • 27
  • 58
  • Did you try Layout Inspector in Xcode? It will clearly show you if you have any unwanted views in between and what constraints exactly are applied in runtime. – lazarevzubov Dec 03 '21 at 06:54
  • Yes, it is properly done – Jay Vyas Dec 03 '21 at 11:05
  • How do you organize these two views? Isn't it a table view by any chance? If so, this might be the answer (and the right question too): https://stackoverflow.com/questions/69461934/extra-space-between-uitableviewsections-in-ios-15 – lazarevzubov Dec 03 '21 at 13:38

1 Answers1

2

The "blank space" is almost certainly the Page View Controller's built-in UIPageControl.

Here's a quick example, with two views... the top view has a UIPageViewController added as a child view controller, and the Top of the bottom view is constrained to the Bottom of the top view:

enter image description here

Notice the "empty space" ...

Using Xcode's Debug View Hierarchy, it's pretty obvious why:

enter image description here

So, if I set a background color on the Top view, I see this:

enter image description here

It appears to be empty space, because the default Page Control uses tinted white dots - so we don't see anything on a white background.


Edit

The PageControl is automatically shown if your controller's DataSource implements both of these optional methods:

optional func presentationCount(for pageViewController: UIPageViewController) -> Int

optional func presentationIndex(for pageViewController: UIPageViewController) -> Int

Removing one or both will automatically remove the page control.

DonMag
  • 69,424
  • 5
  • 50
  • 86