Disabling user interaction of the current view on screen

前端 未结 7 631
一个人的身影
一个人的身影 2021-01-31 02:52

My app has many views and their respective controllers. Now I have a set of model classes with business logic in them. One of the model classes(subclass of NSObject) has the res

7条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 03:48

    I am a little hesitant to disable interactions for the entire app - this is too aggressive and too intrusive, what happens when the view controller is inside a split view controller? Then both view controllers will be disabled!

    Instead, you could create a clear-colored view controller and presented it modally, see example below for Swift 2:

    private func TransparentViewController() -> UIViewController {
      let transparentViewController = UIViewController(nibName: nil, bundle: nil)
      transparentViewController.modalPresentationStyle = .OverCurrentContext
      transparentViewController.modalTransitionStyle = .CrossDissolve
      transparentViewController.view.backgroundColor = UIColor.clearColor()
      return transparentViewController
    }
    

    And now you can present it from within your view controller, before presenting the HUD:

    let transparentViewController = TransparentViewController()
    self.presentViewController(transparentViewController, animated:false, completion: nil) 
    

    Hope this helps!

提交回复
热议问题