更喜欢HomeIndicatorAutoHidden在iPhone X上不起作用 [英] prefersHomeIndicatorAutoHidden not working on iPhone X

查看:473
本文介绍了更喜欢HomeIndicatorAutoHidden在iPhone X上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在将我的一个应用程序更新为iPhone X,并尝试使用以下方法在显示图像的全屏视图控制器上隐藏主页指示器:

I am currently updating one of my apps to iPhone X and tried to hide the home indicator on a fullscreen viewcontroller showing an image using:

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

不过,这种方法似乎无能为力.即使在一段时间不活动之后,也不会调用它,也不会隐藏home指示器.模拟器似乎确实支持此功能,因为照片"应用程序确实隐藏了主页指示符.

This method seems to do nothing, though. It is never called and the home indicator is never hidden, even after a while of inactivity. The simulator does seem to support this since the Photos app does hide the home indicator.

是否还需要设置其他标志才能使其正常工作?我在多个视图控制器中尝试过,但没有一个显示正确的行为.

Is there some other flag that needs to be set to make this work? I tried it in multiple view controllers and none of them show the correct behaviour.

我也尝试添加

if #available(iOS 11.0, *) {
    self.setNeedsUpdateOfHomeIndicatorAutoHidden()
}

我的viewDidLoad()却无济于事

推荐答案

如果在UINavigationController中显示UIViewController,则必须覆盖childViewControllerForHomeIndicatorAutoHidden()函数:

If you show your UIViewController in UINavigationController, you have to override childViewControllerForHomeIndicatorAutoHidden() function:

extension UINavigationController {
    open override func childViewControllerForHomeIndicatorAutoHidden() -> UIViewController? {
        return topViewController
    }
}

或者,如果像父视图控制器的子视图一样显示UIViewController,则还必须重写此功能并返回子视图控制器.

Or if you show your UIViewController like subview of parent view controller, you also have to override this function and return child view controller.

这篇关于更喜欢HomeIndicatorAutoHidden在iPhone X上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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