UINavigationController inside UIPageViewController with vertical scrolling, broken navigation bar height

♀尐吖头ヾ 提交于 2019-12-10 10:09:26

问题


I'm using a UIPageViewController to display few controllers, the first one is UINavigationController, on first sight it looks fine, but when you scroll to next one, the first navigation bar changes the height, and puts title directly under status bar. I've already searched stack overflow but couldn't find any answer to my problem.

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


回答1:


I fixed this in a very hacky way – subclassed UINavigationController and swizzled its navigationBar's setCenter: method (swizzling done with Aspects library):

// 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 child controller of navigation controller because otherwise navigation bar still would get wrong position at first appear:

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

Probably there is right way to do it, but I didn't have time.



来源:https://stackoverflow.com/questions/23471624/uinavigationcontroller-inside-uipageviewcontroller-with-vertical-scrolling-brok

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!