我有一个带视频播放器的iOS应用,当视频正在播放时(风景,全屏)我想隐藏iPhone X上的家用指示器。我试过
if (@available(iOS 11.0, *)) {
[self setNeedsUpdateOfHomeIndicatorAutoHidden];
}
以及
-(BOOL)prefersHomeIndicatorAutoHidden{
return YES;
}
但没有运气。有没有人有任何想法?
答案 0 :(得分:4)
实现容器视图控制器时,覆盖 如果你愿意,可以使用childViewControllerForHomeIndicatorAutoHidden()方法 一个你的孩子查看控制器,以确定是否显示 视觉指示器。如果这样做,系统会调用 首选返回视图的HomeIndicatorAutoHidden()方法 控制器。如果方法返回nil,则系统调用 首选的是当前视图控制器的HomeIndicatorAutoHidden()方法
因此,如果您使用的是childViewController
,那么需要实施childViewControllerForHomeIndicatorAutoHidden
as -
<强>夫特强>
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()
}
}
}
目标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 true;
}
-(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];
}
}
输出 -