Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on @Brian suggestion I made this code:</p> <pre><code>- (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat height = navigationBar.frame.size.height; CGFloat y = scrollView.bounds.origin.y; if (y &lt;= 0) { CGRect frame = navigationBar.frame; frame.origin.y = 0; navigationBar.frame = frame; } else if (tableView.contentSize.height &gt; tableView.frame.size.height) { CGFloat diff = height - y; CGRect frame = navigationBar.frame; frame.origin.y = -y; navigationBar.frame = frame; CGFloat origin = 0; CGFloat h = height; // height of the tableHeaderView if (diff &gt; 0) { origin = diff; h = y; } frame = tableView.frame; frame.origin.y = origin; frame.size.height = tableView.superview.frame.size.height - origin; tableView.frame = frame; CGRect f = CGRectMake(0, 0, tableView.frame.size.width, h); UILabel* label = [[UILabel alloc] initWithFrame:f]; tableView.tableHeaderView = label; [label release]; } } </code></pre> <p>My code has a <code>UITableView</code> but should work with any scrollable component. If you have other components than the navigationBar and the <code>UIScrollView</code> subclass, you should change the way the height of the scrollable component is calculated. Something like this:</p> <pre><code>frame.size.height = tableView.superview.frame.size.height - origin - otherComponentsHeight; </code></pre> <p>I needed to add a dumb <code>tableHeaderView</code> to have the desired behaviour. The problem was that when scrollViewDidScroll: is called the content has an offset, but the apparience in Mobile Safari is that the content is not scrolled until the navigationBar fully disappears. I tried first changing the <code>contentOffset</code>.y to 0, but obviously it didn't work since all the code relies on the scrolling mechanism. So I just added a <code>tableHeaderView</code> whose height is exactly the scrolled offset, so the header is never really seen, and the content appears to not scroll until the <code>navigationBar</code> fully disappears.</p> <p>If you don't add the dumb t<code>ableHeaderView</code>, then the scrollable component appears to scroll behind the <code>navigationBar</code>.</p> <p><img src="https://i.stack.imgur.com/RSiVR.png" alt="enter image description here"></p> <p>With the <code>tableHeaderView</code>, the scrollable component is actually scrolling (as seen in the <code>scrollbar</code>), but since there is a <code>tableHeaderView</code> whose height is exactly the same than the scrolled <code>offset</code>, the scrollable content appears to not be scrolling until the <code>navigationBar</code> fully disappears:</p> <p><img src="https://i.stack.imgur.com/0fei4.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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