如何隐藏tableview上方的自定义视图

时间:2017-12-11 15:33:54

标签: ios swift xcode

我的tableView里面有一个UIView,只需按一下按钮即可消失视图。

因为UIView位于tableView内(不是作为单元格,而是位于tableView之上),我无法设置高度限制并在0之后进行。 / p>

enter image description here

这是我使用的代码:

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()
})

我也尝试将infoView设置为nil(但没有发生任何事情)

如果你不理解我说的话,请发表评论。

提前致谢。

2 个答案:

答案 0 :(得分:0)

最简单的方法是隐藏它,每个视图都隐藏了属性。 https://developer.apple.com/documentation/uikit/uiview/1622585-hidden

答案 1 :(得分: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()

        })
相关问题