Skip to content

Instantly share code, notes, and snippets.

@ellneal
Created April 30, 2012 11:06
Show Gist options
  • Save ellneal/2557400 to your computer and use it in GitHub Desktop.
Save ellneal/2557400 to your computer and use it in GitHub Desktop.
Static View at top of UIScrollView - place in layoutSubviews
UIView *staticHeaderView = <#static view#>;
CGRect visibleBounds = self.bounds;
CGRect staticHeaderFrame = staticHeaderView.frame;
CGRect contentRect = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);
if (CGRectGetMinY(visibleBounds) < CGRectGetMinY(contentRect)) {
staticHeaderFrame = CGRectMake(visibleBounds.origin.x, CGRectGetMinY(contentRect), staticHeaderFrame.size.width, staticHeaderFrame.size.height);
}
else {
staticHeaderFrame = CGRectMake(visibleBounds.origin.x, CGRectGetMinY(visibleBounds), staticHeaderFrame.size.width, staticHeaderFrame.size.height);
}
staticHeaderView.frame = headerFrame;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment