UINavigationController inside a UIPageViewController with vertical scroll, broken navigation bar height

I use the UIPageViewController to display several controllers, the first of which is the UINavigationController, at first glance it looks fine, but when you go to the next, the first navigation bar changes its height and places the title directly on the status bar, I already looked for a stack overflow, but could not find the answer to my problem.

Simple demo: https://github.com/augard/PageScrollingBug

+3
ios cocoa-touch uikit ios7 uipageviewcontroller
source share
1 answer

I fixed this in a very hacky way - subclassed the UINavigationController and swizzled its navigationBar setCenter: method (swizzling done with Aspects ):

 // In subclassed UINavigationController: - (void) viewDidLoad { [super viewDidLoad]; // This just fixes this bug: http://stackoverflow.com/q/23471624/299063 UINavigationBar *navigationBar = self.navigationBar; [navigationBar aspect_hookSelector:@selector(setCenter:) withOptions:AspectPositionInstead usingBlock:^(id<AspectInfo> aspectInfo) { NSValue *centerValue = aspectInfo.arguments[0]; CGPoint center = [centerValue CGPointValue]; CGPoint fixedCenter = CGPointMake(center.x, 20 + navigationBar.bounds.size.height/2); [[aspectInfo originalInvocation] setArgument:&fixedCenter atIndex:2]; [[aspectInfo originalInvocation] invoke]; } error:nil]; } 

I also had to set automaticallyAdjustsScrollViewInsets to NO in the child controller of the navigation controller, because otherwise the navigation bar would still have the wrong position first:

 // In child controller of UINavigationController. self.automaticallyAdjustsScrollViewInsets = NO; 

There may be a right way to do this, but I didn't have the time.

0
source share

All Articles