I want to place a Custom UIView over every view controller screen. I want to do this to show the download progress of video. I create a custom view using xib and use this code -:
let window = UIApplication.shared.keyWindow!
window.subviews(CustomView)
but this code is not working how to resolve this issue.
UIApplication.topWindow.addSubview(CustomView)
extension UIApplication {
static var topWindow: UIWindow {
if #available(iOS 15.0, *) {
let scenes = UIApplication.shared.connectedScenes
let windowScene = scenes.first as? UIWindowScene
return windowScene!.windows.first!
}
return UIApplication.shared.windows.filter { $0.isKeyWindow }.first!
}
}
You can write this code to add the subview in the viewcontroller.
let window = UIApplication.shared.keyWindow!
window.addSubview(CustomView)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.