[英]Add subview on the top of every ViewController
I want to place a Custom UIView over every view controller screen.我想在每个视图 controller 屏幕上放置一个自定义 UIView。 I want to do this to show the download progress of video.
我想这样做以显示视频的下载进度。 I create a custom view using xib and use this code -:
我使用 xib 创建了一个自定义视图并使用此代码-:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.