akaco
akaco

Reputation: 673

Update UIView frame size inside a UITableView - swift

I have a UIView inside a UITableView like this

enter image description here

The problem is when I try to resize height of my UIView programmatically ,the existing cells inside of UITableView didn't move up
i have been tried update UITableview size ,

UITableviewwrapperview 

and I have been try update

TableView.contentInset

TableView.contentOffset

size,remove Auto Layout and Auto Layout , but all same result.

this is my code :

@IBAction func SwitchChanged(sender: UISwitch) {

        if sender.on {
            self.ViewBOX.frame.size.height =  self.ViewBOX.frame.size.height + 275


            var  Frame = self.TableView.tableHeaderView!.frame
            Frame.size.height = self.ViewBOX.frame.size.height;
            TableView.tableHeaderView?.frame = Frame



        } else {
           self.ViewBOX.frame.size.height =  self.ViewBOX.frame.size.height - 275


            var  Frame = self.TableView.tableHeaderView!.frame
            Frame.size.height = self.ViewBOX.frame.size.height;
            TableView.tableHeaderView?.frame = Frame

        }

    }

and this is result image

1 : enter image description here

2 : after update

enter image description here

Someone please help me and explain which part I missed .

thanks

Upvotes: 1

Views: 2128

Answers (2)

Mahesh Agrawal
Mahesh Agrawal

Reputation: 3358

Your code should look like this if you want to change this in a good way.

@IBAction func SwitchChanged(sender: UISwitch) {
    UIView.animateWithDuration(0.3, animations: {
        if sender.on {
            self.ViewBOX.frame.size.height =  self.ViewBOX.frame.size.height + 275
        } else {
           self.ViewBOX.frame.size.height =  self.ViewBOX.frame.size.height - 275
        }
        TableView.tableHeaderView = self.ViewBOX
    }, completion: {
    })
}

Upvotes: 1

Hindu
Hindu

Reputation: 2914

you need to re-assign view in table header each time when you change your header view frame.

YourView.frame =  Frame
TableView.tableHeaderView = YourView

And Remove :

TableView.tableHeaderView?.frame = Frame

Thanks

Upvotes: 2

Related Questions