IOS 控制GLKView绘制区域,适配“刘海”不绘制

与其控制GLKView的大小,或是在游戏层面避开“刘海”,不如直接控制window大小剔除“刘海”区域,view层使用通用的绘制方案。

class AppDelegate: UIResponder, UIApplicationDelegate {
    
    
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
    
		
		// 判断是否有刘海
        if (window?.safeAreaInsets.bottom ?? 0 > 0)
        {
    
    
            var bounds         = UIScreen.main.bounds
            // 直接把刘海剔除
            bounds.size.width -= 44
            window?.frame      = bounds
        }
        
        return true
    }
}

猜你喜欢

转载自blog.csdn.net/tom_221x/article/details/113761745