在运行时更改tableview的高度

Shubham

喂,我正在创建一个菜单作为表格视图,并在单击按钮时切换其可见性。我实际上是在改变它的高度,但是改变tableview的高度只会影响tableview而不会影响其中的单元格。TableView也有阴影,如果我删除阴影,则效果很好。请帮忙。这是一些代码片段

let _initialTableFrame = CGRectMake(self.view.frame.size.width - 150, 68, 140, 0)
    _topMenuTableView = UITableView(frame: _initialTableFrame)
    _topMenuTableView.delegate = self
    _topMenuTableView.dataSource = self
    _topMenuTableView.rowHeight = 35
    _topMenuTableView.tag = 100
    _topMenuTableView.alpha = 0.9
    _topMenuTableView.tableFooterView = UIView()
    _topMenuTableView.scrollEnabled = false

    _topMenuTableView.layer.cornerRadius = 5
    _topMenuTableView.layer.shadowColor = UIColor.blackColor().CGColor
    _topMenuTableView.layer.shadowOffset = CGSizeMake(0, 0)
    _topMenuTableView.layer.shadowRadius = 5.0
    _topMenuTableView.layer.shadowOpacity = 1 
func toogleTopMenu()
{
    if _isTopMenuVisible
    {
        let _currentTopMenuFrame = _topMenuTableView.frame
        let _tempFrame = CGRectMake(_currentTopMenuFrame.origin.x, _currentTopMenuFrame.origin.y, _currentTopMenuFrame.size.width, 0)


        UIView.animateWithDuration(0.2, animations: {self._topMenuTableView.frame = _tempFrame})
        _isTopMenuVisible = false
    }
    else
    {
        let _currentTopMenuFrame = _topMenuTableView.frame
        let _tempFrame = CGRectMake(_currentTopMenuFrame.origin.x, _currentTopMenuFrame.origin.y, _currentTopMenuFrame.size.width, 38)

        UIView.animateWithDuration(0.2, animations: {self._topMenuTableView.frame = _tempFrame})
        _isTopMenuVisible = true
    }
}
贝迪

这是因为您仅更改tableView的框架,而不更改 tableViewCellHeight

尝试这个

    func toogleTopMenu()
{
    if _isTopMenuVisible
    {
        let _currentTopMenuFrame = _topMenuTableView.frame
        let _tempFrame = CGRectMake(_currentTopMenuFrame.origin.x, _currentTopMenuFrame.origin.y, _currentTopMenuFrame.size.width, 0)

        UIView.animateWithDuration(0.2, animations: {self._topMenuTableView.frame = _tempFrame
_topMenuTableView.rowHeight = //whatever Height you want to assign
_topMenuTableView.reloadDate()
})

        _isTopMenuVisible = false
    }
    else
    {
        let _currentTopMenuFrame = _topMenuTableView.frame
        let _tempFrame = CGRectMake(_currentTopMenuFrame.origin.x, _currentTopMenuFrame.origin.y, _currentTopMenuFrame.size.width, 38)
    UIView.animateWithDuration(0.2, animations: {self._topMenuTableView.frame = _tempFrame
_topMenuTableView.rowHeight = //whatever Height you want to assign
_topMenuTableView.reloadDate()
})
    _isTopMenuVisible = true
}
}

会有所帮助的。谢谢

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章