How to add subview to UIWindow Scene iOS 13

190 views Asked by At

I have created a in house framework which works perfectly fine till iOS 12, as I am adding a button (floating button) on window so that it is visible on entire app.

I have created a UIWindow class to add a button, check below code

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)
    }
}

And in app delegate, in didfinishlaunchingwithoption I am calling using shared instance

 FloatingButtonController.sharedInstance.button.addTarget(self, action: #selector(AppDelegate.floatingButtonWasTapped), for: .touchUpInside)

But from iOS 13 button is not visible on app as UIWindowscene is introduce.

I need help to add floating button on my app window in iOS 13 using UIWindowscene.

Note: As a workaround I have removed scene from my project and its working well, But I need more flexible solution which can used on iOS 13 and above. So that I just need to update my framework .

0

There are 0 answers