【问题标题】:UIViewController status bar top insetUIViewController 状态栏顶部插图
【发布时间】:2017-11-08 21:18:40
【问题描述】:

我在我的应用中使用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 的大小。当应用程序启动时,我的“状态栏”只是普通的 UIView,背景颜色位于系统状态栏后面。但是当我滚动到下一页/上一页时,它会偏移几个像素。我怎么能统一呢?为什么我在上面得到这么小的偏移量?

我正在使用 Storyboard 对视图控制器进行建模:

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

当我滚动到下一页时:

这个白色区域不应该在那里...旋转设备后一切都很好。

【问题讨论】:

    标签: ios iphone swift uiviewcontroller uipageviewcontroller


    【解决方案1】:

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

    yourView.frame.origin.y = -5
    

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

    【讨论】:

    • 常量看起来不错,在将设备旋转到横向并返回到纵向后,它会神奇地回到顶部,就像它应该的那样......所以设置 -5 将使它在旋转后向上偏移。所有视图控制器的顶部状态栏约束都设置为 0
    • 尝试在您的viewWillAppear yourView.layoutIfNeeded 中执行此操作
    • 没有帮助。我已经通过捕获它来检查 xCode 中的界面 - 主 UIView 在整个屏幕上,只是里面的内容有这个偏移量。
    • 我将状态栏移动到frame.origin.y 0 并在整个视图控制器上调用view.layoutIfNeeded。看起来很完美。丹克:)
    • @Preetygeek,太棒了!祝你的项目和布局好运 =)
    猜你喜欢
    • 2015-07-17
    • 2011-09-12
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 2017-09-21
    • 1970-01-01
    相关资源
    最近更新 更多