avigationController里面UIPageViewC

avigationController里面UIPageViewC

本文介绍了UINavigationController里面UIPageViewController与垂直滚动,破碎的导航栏高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用UIPageViewController显示少数控制器,第一个是UINavigationController,看起来很好,但当你滚动到下一个,第一个导航栏更改高度,并放置标题直接在状态栏。我已经搜索堆栈溢出,但找不到任何答案我的问题。

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.

简单的演示:

推荐答案

我固定这个非常hacky方式 - 子类 UINavigationController 并且混合它的 navigationBar setCenter: 方法(使用库进行swizzling):

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];
}



我还必须设置 automaticallyAdjustsScrollViewInsets NO 在导航控制器的子控制器中,否则导航栏仍然会出现错误的位置:

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.

这篇关于UINavigationController里面UIPageViewController与垂直滚动,破碎的导航栏高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:06