我使用 UIPageViewController 来显示几个控制器,第一个是 UINavigationController,乍一看它看起来不错,但是当您滚动到下一个时,第一个导航栏会更改高度,并将标题直接放在状态栏下方。我已经搜索了堆栈溢出,但找不到我的问题的任何答案。
简单演示:https://github.com/augard/PageScrollingBug https://github.com/augard/PageScrollingBug
我用一种非常hacky的方式修复了这个问题——子类化UINavigationController
并混合它的navigationBar
's setCenter:
方法(用Aspects https://github.com/steipete/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];
}
我还必须设置automaticallyAdjustsScrollViewInsets
to NO
在导航控制器的子控制器中,否则导航栏在第一次出现时仍然会出现错误的位置:
// In child controller of UINavigationController.
self.automaticallyAdjustsScrollViewInsets = NO;
也许有正确的方法可以做到这一点,但我没有时间。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)