Last active
August 29, 2015 14:04
-
-
Save martinhering/068edb5908fe04c677e6 to your computer and use it in GitHub Desktop.
Managing scrollview.contentInset adjustment manually
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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