Change a specific row height of a uitableviewcell while scrolling a uitableview

I have a UITableview with 2 sections, 1 row in the 1st section and a variable number of rows for the second section. When the user scrolls the table up (moving the finger up), then the table view does this by default, but when the user is at the top of the uitableview and scrolling down (the finger moves down), then it should look like the first cell in the height of the first section increases as much. as the user scrolls down (and releasing the touch changes the height of the line back to its original height of 100). I tried

-(void)scrollViewDidScroll:(UIScrollView*)scrollView{ if(scrollView.contentOffset.y < 0){ [mainTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection: 0]] withRowAnimation:UITableViewRowAnimationNone]; } } -(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{ if(indexPath.section == 0 && tableView.contentOffset.y < 0){ return -tableView.contentOffset.y+100;//Default height is 100 } } 

but the reloadRows method resets the value of contentOffset to 0, so the tableview just stutters when I compress. It seems like if this does not work, I will have to write everything on a UIScrollView, and it seems like a huge pain without reusable cells.

Does anyone have any suggestions?

+6
source share
1 answer

No need to reload the line, I just changed the frame directly. Make sure you set cell.layer.masksToBounds = YES and make the subViews in the cell larger than the original cell height.

 -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (mainTable.contentOffset.y < 0) { UITableViewCell *cell = [mainTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; float rawr = mainTable.contentOffset.y; cell.frame = CGRectMake(cell.frame.origin.x, rawr, cell.frame.size.width, 100-rawr); } } 
+9
source

Source: https://habr.com/ru/post/907550/


All Articles