gpt4 book ai didi

ios - 隐藏 iPhone X 的主页指示器

转载 作者:技术小花猫 更新时间:2023-10-29 11:05:08 24 4
gpt4 key购买 nike

我有一个带有视频播放器的 iOS 应用程序,当视频正在播放时(横向,全屏)我想隐藏 iPhone X 上的主页指示器。我已经尝试过

if (@available(iOS 11.0, *)) {
[self setNeedsUpdateOfHomeIndicatorAutoHidden];
}

还有

-(BOOL)prefersHomeIndicatorAutoHidden{
return YES;
}

但运气不好。有人知道吗?

最佳答案

When implementing a container view controller, override childViewControllerForHomeIndicatorAutoHidden() method if you want one your child view controllers to determine whether to display the visual indicator. If you do, the system calls the prefersHomeIndicatorAutoHidden() method of the returned view controller. If the method returns nil, the system calls the prefersHomeIndicatorAutoHidden() method of the current view controller

因此,如果您正在使用 childViewController,则需要实现 childViewControllerForHomeIndicatorAutoHidden作为-

swift

extension UINavigationController {
open override func childViewControllerForHomeIndicatorAutoHidden() -> UIViewController? {
return DemoViewController.loadFromNib()
}
}

//DemoViewController is childViewController
class DemoViewController: UIViewController {
static func loadFromNib() -> DemoViewController{
let storyBoardInst = UIStoryboard(name: "Main", bundle: nil)
return storyBoardInst.instantiateViewController(withIdentifier: "DemoViewController") as! DemoViewController
}

override func prefersHomeIndicatorAutoHidden() -> Bool {
return true
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
view.backgroundColor = .red
if #available(iOS 11.0, *) {
//Notifies UIKit that your view controller updated its preference regarding the visual indicator
setNeedsUpdateOfHomeIndicatorAutoHidden()
}
}
}

Objective-C -

@interface UINavigationController(custom)
@end
@implementation UINavigationController(custom)
-(UIViewController *)childViewControllerForHomeIndicatorAutoHidden{
return [self.storyboard instantiateViewControllerWithIdentifier:@"DemoViewController"];
}
@end
//DemoViewController is childViewController
@interface DemoViewController ()
@end
@implementation DemoViewController
-(BOOL)prefersHomeIndicatorAutoHidden{
return YES;
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
self.view.backgroundColor = [UIColor redColor];
//Notifies UIKit that your view controller updated its preference
// regarding the visual indicator
if (@available(iOS 11.0, *)) {
[self setNeedsUpdateOfHomeIndicatorAutoHidden];
}
}

输出-

enter image description here

关于ios - 隐藏 iPhone X 的主页指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47322175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com