HomeiOS Developmentios - Block touches on something when customized pop-up is proven

ios – Block touches on something when customized pop-up is proven


The person can add information to a server in my Swift 5/Xcode 12.4 app by clicking a button within the navigation bar. Whereas that is occurring (asynchronously in a background thread) I am displaying a customized pop-up and not one of the common buttons (together with the buttons within the navigation bar) must be clickable:

static func showIndicator(view: UIView) {
    let parentView = UIView(body: view.body)
    parentView.backgroundColor = UIColor.purple.withAlphaComponent(0.5) //purple just for testing, going to be set to 0.0 later
        
    let indicatorContainer = UIView()
    let width = 80
    let top = 80
        
    indicatorContainer.body = CGRect(x: 0, y: 0, width: width, top: top)
    indicatorContainer.middle = view.middle
    indicatorContainer.backgroundColor = UIColor.darkGray.withAlphaComponent(0.97)
    indicatorContainer.layer.cornerRadius = 8
    indicatorContainer.clipsToBounds = true
        
    let indicatorView = UIActivityIndicatorView(model: UIActivityIndicatorView.Model.massive)
    indicatorView!.middle = CGPoint(x: width/2, y: top/2)
        
    indicatorContainer.addSubview(indicatorView!)
    parentView.addSubview(indicatorContainer)
    view.addSubview(parentView)
    indicatorView!.startAnimating()
}

Known as from the UIViewController with:

Toaster.showIndicator(view: self.view)

This makes it not possible to the touch the buttons,… within the common UIView however it does not cowl the navigation bar and the person may theoretically begin the add course of a second time (amongst different issues), which is not good. I discovered two methods to forestall this from occurring:

  1. Disable the buttons within the navigation bar briefly with uploadButton.isEnabled = false. This has the drawback that the buttons flip gray.

  2. Cowl the entire space, together with the navigation bar, with an invisible UIView however this additionally covers the standing bar and I am undecided if it is okay to easily entry the window like that:

     static func showIndicator(view: UIView) {
         let window = UIApplication.shared.home windows.first(the place: { $0.isKeyWindow })!
         let parentView = UIView(body: window.body)
    
         ...
    
         parentView.addSubview(indicatorContainer)
         window.addSubview(parentView)
         indicatorView!.startAnimating()
     }
    

I find out about userInteractionEnabled however you may’t use it for UIBarButtonItems and there are too many different clickable UI parts beneath the pop-up to disable all of them briefly.

What’s the popular methodology for blocking button presses on something (= beneath the pop-up view) within the app whereas one thing else that should not be interrupted by person interplay is occurring?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments