How do I add a modal view on top of a UITableViewController that disables user interaction with

52 views Asked by At

I would like to be able to add a modal view in front of my table view, that is displayed relative to the view rather than relative to the table view (as shown in the photos)1. Also how do I prevent the user interacting with the table behind. I have included the code used to animate my view in also. Thanks in advance!

func newPersonAnimateIn() {
    self.overlayView.transform = CGAffineTransform.identity
    self.view.addSubview(overlayView)

    overlayView.center = self.view.center
    overlayView.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
    overlayView.alpha = 0

    UIView.animate(withDuration: 0.4) {
        //self.visualEffectView.effect = self.effectHolder
        self.overlayView.alpha = 1
        self.overlayView.transform = CGAffineTransform.identity
    }
    personName.becomeFirstResponder()
}

func newPersonAnimateOut() {
    self.view.endEditing(true)
    UIView.animate(withDuration: 0.3, animations: {
        self.overlayView.alpha = 0
        self.overlayView.transform = CGAffineTransform.identity
    }){(success:Bool) in
        self.overlayView.removeFromSuperview()
    }
    personName.text = ""
}

@IBAction func addPerson(_ sender: UIBarButtonItem) {
    newPersonAnimateIn()
}

@IBAction func continueButton(_ sender: Any) {
    newPersonAnimateOut()
}
1

There are 1 answers

2
Juraj Antas On

Maybe this would be enough:

self.tableView.isUserInteractionEnabled = false

or create another view under your modal view that covers full screen and set isUserInteractionEnabled = false