Im trying to resize the tableview’s height with a animation, it works fine by animating the tableview’s frame.size.height.
The problem is, i have a tableview that is 200px height and scrolled to the bottom, i want to animate this to 100px, i run a simple
[UIView animateWithDuration:0.245f animations:^{
CGRect frame = tableview.frame;
frame.size.height = 100.f;
tableview.frame = frame;
}];
this works fine, but after i resized it it is no longer scrolled to the bottom of the tableview. i want the tableview to always be scrolled at the bottom while animating. i tried alot of differnet things like calling
[tablview scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
right before/after i start the resize animation, but i have not managed to get them to sync 100%. Is there a way to resize the tableview while the bottom of the tableview displays the last element of the scrollview.
I found a solution for my problem, there might very well be a better solution but this actually works quite well 🙂
Before i start animating i see if the contentSize.height is larger than the target height, if so i do following:
this will put the tableview in a minus origin.y, then i have wrapped the tableview inside a “parent” uiview with clip sub views = YES.
Then i have a “completed” animation block that “resets” to the target values.