0

I have a tableView with a UIView inside it and I want with the tap of a button to disappear the view.

Because the UIView is inside the tableView (not as a cell, but above the tableView) I can't set a height constraint and make it after 0.

enter image description here

This is the code I use:

UIView.animate(withDuration: 2.0, animations: { () -> Void in
  self.infoView.frame = CGRect(x: 0 ,y: 0, width: self.view.frame.width, height: 0)
  self.view.layoutIfNeeded()
})

I also tried to set infoView equal to nil (but nothing happened)

Please leave a comment if you don't understand something I said.

Thanks in advance.

mike vorisis
  • 2,625
  • 6
  • 38
  • 71

2 Answers2

0

Simplest way is hide it, each view has property hidden. https://developer.apple.com/documentation/uikit/uiview/1622585-hidden

Dmytro
  • 1
  • 2
0
change your code


UIView.animate(withDuration: 2.0, animations: { () -> Void in
            self.infoView.frame = CGRect(x: 0 ,y: 0, width: 0, height: 0)
            self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.automatic
            self.tableView.reloadData()

        })
Jeetendra Kumar
  • 490
  • 3
  • 9