Search code examples
iosiphoneswiftuiviewcontrolleruipageviewcontroller

UIViewController status bar top inset


I'm using SCPageViewController in my app:

class RootPageViewController: UIViewController {

    var pageViewController : SCPageViewController = SCPageViewController()

    var viewControllers = [UIViewController]() 
    ......

in viewDidLoad I'm configuring it:

self.pageViewController.setLayouter(SCPageLayouter(), animated: false, completion: nil)
self.pageViewController.easingFunction = SCEasingFunction(type: SCEasingFunctionType.linear) 
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
self.addChildViewController(self.pageViewController)
self.pageViewController.view.frame = self.view.bounds
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMove(toParentViewController: self)

I'm setting size of content view controllers in SCPageViewController data source method to be size of RootPageViewController. When app launches, I have my "status bar" that is just plain UIView with background color behind system status bar. But when I'm scrolling to next/previous page, it is offset by few pixels. How I can unify that? Why I'm getting this small offset on top?

I'm using Storyboards to model view controllers:

Storyboard

This is how it looks after app launches (as expected):

expected

And when I scroll to next page:

enter image description here

This white area shouldn't be there... Everything is fine after I rotate device.


Solution

  • You could change the originY for the view to move it up a bit:

    yourView.frame.origin.y = -5
    

    BUT you should take a look at your constraints and see what happens to them when you change view and see if you could solve it that way instead. Because the solution provided above will move up the view, so you will have - 5 pixels at the bottom.