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,786
  • 6
  • 40
  • 74
  • 2
    Is it possible to use tableHeaderView and then set its height property to zero with tableHeaderView height ? Like this https://stackoverflow.com/a/34689293/3739902 – Darko Dec 11 '17 at 15:39
  • Have you checked outlet? Isn't it nil? – AVerguno Dec 11 '17 at 15:41
  • @user3739902 thank you I tried to set the tableheaderView as nil and did what I wanted, now I will make it with the height to be more beautiful, thanks again – mike vorisis Dec 11 '17 at 15:44
  • @mikevorisis no problem, glad it works. If it's not a problem, would you mind marking the answer as correct ? :) – Darko Dec 11 '17 at 15:45
  • 1
    @user3739902 you have to make an answer to mark it as accepted :P, of course I will as soon as you answer – mike vorisis Dec 11 '17 at 15:48
  • 4
    @user3739902 Comments are not answers. – rmaddy Dec 11 '17 at 15:53

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
  • 500
  • 3
  • 9