I have a testVC. TestVC hasnt storyboard, this viewController has XIB file. I show this VC when i have no internet. And logic for a show this VC like this:
let getVC = NoInternetConnectionVC(nibName: "NoInternetConnectionView", bundle: nil)
if let getWindow = self.window {
getVC.view.tag = 501
getVC.view.frame = getWindow.bounds
getWindow.addSubview(getVC.view)
}
also i have extension for UIViewController
extension UIViewController {
var appDelegate: AppDelegate {
return UIApplication.shared.delegate as! AppDelegate
}
var sceneDelegate: SceneDelegate? {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let delegate = windowScene.delegate as? SceneDelegate else { return nil }
return delegate
}
}
extension UIViewController {
var window: UIWindow? {
if #available(iOS 13, *) {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let delegate = windowScene.delegate as? SceneDelegate, let window = delegate.window else { return nil }
return window
}
guard let delegate = UIApplication.shared.delegate as? AppDelegate, let window = delegate.window else { return nil }
return window
}
}
all clicks in the TestVC
works if i show this View Controller like this:
navController.pushViewController(NoInternetConnectionVC(nibName: "NoInternetConnectionView", bundle: nil), animated: true)
but it doesn't suit me. I need to show NoInternetConnectionVC
like i described above, that is, like this. When i show NoInternetConnectionVC like below all my listeners stop to work
let getVC = NoInternetConnectionVC(nibName: "NoInternetConnectionView", bundle: nil)
if let getWindow = self.window {
getVC.view.tag = 501
getVC.view.frame = getWindow.bounds
getWindow.addSubview(getVC.view)
}
I tried to add line isUserInteractionEnabled
to my code, like this
if let getWindow = self.window {
getVC.view.tag = 501
getVC.view.isUserInteractionEnabled = true //added line
getVC.view.frame = getWindow.bounds
getWindow.addSubview(getVC.view)
}
but it doesnt work
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…