报错:Unbalanced calls to begin/end appearance 。UIWindow弹框无法显示

        创建自定义window窗口时:
        let _window : UIWindow = UIWindow()
        _window.frame = UIScreen.main.bounds
        _window.windowLevel = UIWindow.Level.normal
        _window.rootViewController = UIViewController()
        _window.backgroundColor = UIColor.clear
        _window.makeKeyAndVisible()

创建后直接present一个viewcontroller:
_window.rootViewController?.present(vc, animated: false, completion: {
})

会无法弹出这个窗口,控制台报错为:
Unbalanced calls to begin/end appearance transitions for <XXXViewController: 0x7fcea3730650>.

是因为创建windown时 makeKeyAndVisible() 动画还没完成就present领一个动画造成的,就算把present animated设为false,也还是报错。
解决办法就是把这两个方法拆开,不要放到一起。。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。