为什么当我隐藏它时,状态栏会向后滑动 20 点我的图像? [英] Why is the status bar sliding back of 20 points my image when I hide it?

查看:21
本文介绍了为什么当我隐藏它时,状态栏会向后滑动 20 点我的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIImagePickerController 被调用时,似乎有一个错误.状态栏甚至不应该显示.

There appears to be a bug when UIImagePickerController gets called. The status bar shows up even it shouldn't.

要解决使用子类化的方法:

To workaround that am using subclassing it:

class MyImagePickerController: UIImagePickerController {

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.setNeedsStatusBarAppearanceUpdate()
    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }

    override func childViewControllerForStatusBarHidden() -> UIViewController? {
        return nil;
    }
}

并且我使用此代码显示照片库:

and I use this code show up the Photo Library:

let picker = MyImagePickerController()

    picker.allowsEditing = false
    picker.sourceType = .SavedPhotosAlbum
    picker.modalPresentationStyle = .Popover
    self.presentViewController(picker, animated: true, completion: nil)
    picker.popoverPresentationController?.sourceRect = CGRectMake(0,0,0,0)
    picker.popoverPresentationController?.sourceView = self.view

但是,状态栏被隐藏了,但它通过向下约 20 点的约束滑动连接到视图的图像.我该如何解决?

However, the status bar gets hidden but it slides an image connected to the view via a constraint down of about 20 points. How can I fix that?

推荐答案

我设法通过控制 imagePickerController 中的导航栏来解决这个问题.这可能对您有用,但这取决于您问题的确切上下文(即显示 imagePicker 之前的视图层次结构状态).

I managed to fix this for my case by taking control of the nav bar in the imagePickerController. This may work for you, but it will depend on the precise context of your problem (i.e. state of view hierarchy before imagePicker is shown).

与我的之前的解决方案一样,您继承了 UIImagePickerController.这又是 UINavigationController 的子类,因此您可以访问它的导航栏.

As with my previous solution, you subclass UIImagePickerController. This is in turn a subclass of UINavigationController, so you can get at it's navbar.

class WNImagePickerControllerSwift: UIImagePickerController {

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.setNeedsStatusBarAppearanceUpdate()
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.setNavBar()
    }

    override func prefersStatusBarHidden() -> Bool {
        self.setNavBar()
        return true
    }

    override func childViewControllerForStatusBarHidden() -> UIViewController? {
        return nil;
    }

    func setNavBar() -> Void {
        self.setNavBar(65)
    }


    func setNavBar(height: CGFloat) -> Void {
        var frame = self.navigationBar.frame;
        frame.size.height = height;
        self.navigationBar.frame = frame;
    }

}

setNavBar 必须恰好在这两个地方被调用 - 一次是在调用 prefersStatusBarHidden 时的动画转换之前,一次是在转换之后.如果直接在 viewWillAppear 中调用它是行不通的.

setNavBar has to be called in precisely those two places - once before the animation transition when prefersStatusBarHidden is invoked, and once again after the transition. It won't work if you call it directly in viewWillAppear.

无论如何都值得一试,玩弄那个神奇的数字 65 以适应您所追求的导航栏高度.

Anyway it's worth a try, playing around with that magic number 65 to suit the navbar height that you are after.

这篇关于为什么当我隐藏它时,状态栏会向后滑动 20 点我的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆