Skip to content

Instantly share code, notes, and snippets.

@martinhering
Last active August 29, 2015 14:04
Show Gist options
  • Save martinhering/068edb5908fe04c677e6 to your computer and use it in GitHub Desktop.
Save martinhering/068edb5908fe04c677e6 to your computer and use it in GitHub Desktop.
Managing scrollview.contentInset adjustment manually
- (void) setScrollView:(UIScrollView*)scrollView contentInsets:(UIEdgeInsets)edgeInsets byAdjustingForStandardBars:(BOOL)adjustStandardBars
{
if (adjustStandardBars)
{
UINavigationController* navController = self.navigationController;
if (navController)
{
CGRect navBarFrame = self.navigationController.navigationBar.frame;
edgeInsets.top += CGRectGetMinY(navBarFrame); // statusbar
edgeInsets.top += CGRectGetHeight(navBarFrame); // navbar height
if (!self.navigationController.toolbarHidden) {
CGRect toolbarFrame = self.navigationController.toolbar.frame;
edgeInsets.bottom += CGRectGetHeight(toolbarFrame); // toolbar height
}
}
if (self.tabBarController)
{
CGRect tabBarFrame = self.tabBarController.tabBar.frame;
edgeInsets.bottom += CGRectGetHeight(tabBarFrame); // tabbar height
}
}
scrollView.contentInset = edgeInsets;
scrollView.scrollIndicatorInsets = edgeInsets;
if (CGPointEqualToPoint(scrollView.contentOffset, CGPointZero)) {
scrollView.contentOffset = CGPointMake(0,-edgeInsets.top);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment