ios13 - 如何将子视图添加到 UIWindow 场景 iOS 13
问题描述
我创建了一个内部框架,它在 iOS 12 之前运行良好,因为我在窗口上添加了一个按钮(浮动按钮),以便它在整个应用程序中可见。
我创建了一个 UIWindow 类来添加一个按钮,检查下面的代码
public class FloatingButtonWindow: UIWindow {
public var button: UIButton?
public init() {
super.init(frame: UIScreen.main.bounds)
backgroundColor = nil
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
guard let button = button else { return false }
let buttonPoint = convert(point, to: button)
return button.point(inside: buttonPoint, with: event)
}
}
在应用程序委托中,在 didfinishlaunchingwithoption 我使用共享实例调用
FloatingButtonController.sharedInstance.button.addTarget(self, action: #selector(AppDelegate.floatingButtonWasTapped), for: .touchUpInside)
但是从 iOS 13 开始,由于引入了 UIWindowscene,应用程序上看不到按钮。
我需要帮助才能使用 UIWindowscene 在 iOS 13 中的应用程序窗口上添加浮动按钮。
注意:作为一种解决方法,我已经从我的项目中删除了场景并且它运行良好,但我需要更灵活的解决方案,可以在 iOS 13 及更高版本上使用。所以我只需要更新我的框架。
解决方案
推荐阅读
- android - Why is Unity IAP service not working on Android production version?
- angular - 发送带有某人已登录令牌的标头
- firebase - 使用 Github Action 部署 Firebase
- r - 如何在 Ubuntu 中升级 IRKernel?
- php - Fatal error: require(): Failed opening required 'vendor/autoload.php' in Laravel project/Serpwow API
- python - 使用 selenium 抓取启用 Google 验证码“我不是机器人”的网站
- python - 如何在 VsCode 中定义 %time
- apache-spark - 如何避免过多的数据框查询
- php - php array target value by name instead of number
- typescript - Typescript Generic Constraint where the property of one type depends on the other