与其控制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
}
}