I have a dynamic UITableView, which will insert and delete rows when clicking button.
-(IBAction)foldingClicked:(id)sender
{
self.isInfoFolded = !self.isInfoFolded;
if( self.isInfoFolded)
{
//self.mainTable remove rows
}else
{
//self.mainTable insert rows
}
}
and I did some animation in scrollViewDidScroll:
-(void)scrollViewDidScroll:(UIScrollView*)scrollView
{
CGFloat main_offset = scrollView.contentOffset.y;
//animation
CGRect image_frame = self.imageView.frame;
if((main_offset >= 0 ) && (main_offset <= self.imageView.frame.size.height))
{
image_frame.origin.y = main_offset/2;
}else
{
image_frame.origin.y = image_frame.size.height/2;
}
}
It mostly works fine. But when I
- click button to insert rows. ( the tableView contentSize increase )
- Scroll table view to a big offset.
- click button to delete rows. ( the tableView contentSize decrease )
Result: The table view will scroll up because the decreased contentSize is making the valid contentOffset smaller too, during which process my scrollViewDidScroll method is not invoked, that makes the animation incomplete, and leaving imageView at wrong position in my case.
I tried calling scrollViewDidScroll: right after removing rows. However scrollViewDidScroll: is invoked only once and the contentOffset is '0' in that execute. It's not gradually down to '0' . So is there any way for making scrollViewDidScroll being called continuously like it usually do?