UIViewController 状态栏顶部插入

UIViewController status bar top inset

我在我的应用程序中使用 SCPageViewController

class RootPageViewController: UIViewController {

    var pageViewController : SCPageViewController = SCPageViewController()

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

在 viewDidLoad 中我正在配置它:

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)

我在 SCPageViewController 数据源方法中将内容视图控制器的大小设置为 RootPageViewController 的大小。当应用程序启动时,我的 "status bar" 只是普通的 UIView,系统状态栏后面有背景色。但是当我滚动到 next/previous 页面时,它会偏移几个像素。我怎么能统一呢?为什么我在顶部得到这么小的偏移量?

我正在使用情节提要来为视图控制器建模:

这是应用启动后的样子(如预期):

当我滚动到下一页时:

这个白色区域不应该在那里...旋转设备后一切正常

您可以更改 originY 视图以将其向上移动一点:

yourView.frame.origin.y = -5

但是你应该看看你的constraints,看看当你改变视图时它们会发生什么,看看你是否可以用这种方式解决它。因为上面提供的解决方案会向上移动视图,所以你将在底部有 - 5 个像素。