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

标签 ios objective-c iphone-x

我有一个带有视频播放器的 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/

相关文章:

ios - swift 1.2 : fatal error: unexpectedly found nil while unwrapping an Optional value

objective-c - 使 Cocoa 应用程序可编写 AppleScript 脚本的问题

ios - 如何在 Flutter 中隐藏导航栏(在 iPhone X 上)

ios - 如果部分离开屏幕,子 ViewController 安全区域插图不会更新

objective-c - 如何在 google map sdk iOS 中绘制一个地方到另一个地方的路径?

ios - GameScene SpriteKit 不适合 iPhone X 显示

ios - 用于在 Objective-C 中对二维数组进行排序的优于 O(n^2) 的算法

ios - Apple Pay 演示应用程序 - 错误 : 'Thread 1: signal SIGABRT'

ios - SwiftUI 无法平移图像

c++ - 如何在运行时确定 void * 指针是指向 objective-c 对象还是指向 c++ 对象