Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimate `UITableView` headers when animating `tableHeaderView` in
    primarykey
    data
    text
    <p>For an answer for "<a href="https://stackoverflow.com/questions/341256/how-to-resize-a-tableheaderview-of-a-uitableview/15416193#15416193">How to resize a tableHeaderView of a UITableView?</a>" I created a small project on <a href="https://github.com/besi/ios-quickies/#resizetableheaderviewanimated" rel="nofollow noreferrer">github</a>, which adds a header view to a <code>UITableView</code> and animates both the newly added header view and the cells underneath it.</p> <p>However, as soon as I add header cells I get a nasty UI glitch because the headers don't animate along with the cells of the <code>UITableView</code>:</p> <p>When I add the header the following steps happen:</p> <ol> <li><strong>Problem</strong>: The topmost header jumps to the original position</li> <li>The <code>tableHeaderView</code> and the <code>UITableViewCell</code>s animate together to their final position.</li> </ol> <p>So my question is, how I can make sure that the headers also animate.</p> <p>You can see the effect here, where the <code>Section-1</code> is at the final position, while the cells and the header view are still animating:</p> <p><img src="https://i.stack.imgur.com/1Hzri.png" alt="header glitch"></p> <p>This is the method, where I do the animation:</p> <pre><code>- (void) showHeader:(BOOL)show animated:(BOOL)animated{ CGRect closedFrame = CGRectMake(0, 0, self.view.frame.size.width, 0); CGRect newFrame = show?self.initialFrame:closedFrame; if(animated){ // The UIView animation block handles the animation of our header view [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; // beginUpdates and endUpdates trigger the animation of our cells [self.tableView beginUpdates]; } self.headerView.frame = newFrame; [self.tableView setTableHeaderView:self.headerView]; if(animated){ [self.tableView endUpdates]; [UIView commitAnimations]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload