问题描述
我有一个 UIPageViewController
半透明的状态栏和导航栏。它的 topLayoutGuide
64像素,符合市场预期。
I have a UIPageViewController
with translucent status bar and navigation bar. Its topLayoutGuide
is 64 pixels, as expected.
不过,子视图控制器 UIPageViewController
报告的0像素的 topLayoutGuide
,即使它们是状态栏和导航栏下方显示。
However, the child view controllers of the UIPageViewController
report a topLayoutGuide
of 0 pixels, even if they're shown under the status bar and navigation bar.
这是预期的行为?如果是这样,什么是下一个定位子视图控制器的观点的最好办法真正的 topLayoutGuide
?
Is this the expected behavior? If so, what's the best way to position a view of a child view controller under the real topLayoutGuide
?
(短期使用 parentViewController.topLayoutGuide
,我会考虑一个黑客)
(short of using parentViewController.topLayoutGuide
, which I'd consider a hack)
推荐答案
的答案可能是正确的,我还是发现自己有旅游的围堵树高达找到合适的父视图控制器,让你形容为真正的 topLayoutGuide
。这样我可以手动执行 automaticallyAdjustsScrollViewInsets
。
While this answer might be correct, I still found myself having to travel the containment tree up to find the right parent view controller and get what you describe as the "real topLayoutGuide
". This way I can manually implement automaticallyAdjustsScrollViewInsets
.
这是我正在做的:
在我的表视图控制器(的UIViewController
的一个子类实际上),我有这样的:
In my table view controller (a subclass of UIViewController
actually), I have this:
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
_tableView.frame = self.view.bounds;
const UIEdgeInsets insets = (self.automaticallyAdjustsScrollViewInsets) ? UIEdgeInsetsMake(self.ms_navigationBarTopLayoutGuide.length,
0.0,
self.ms_navigationBarBottomLayoutGuide.length,
0.0) : UIEdgeInsetsZero;
_tableView.contentInset = _tableView.scrollIndicatorInsets = insets;
}
通知的UIViewController
类的方法,这就是我如何实现它们:
Notice the category methods in UIViewController
, this is how I implemented them:
@implementation UIViewController (MSLayoutSupport)
- (id<UILayoutSupport>)ms_navigationBarTopLayoutGuide {
if (self.parentViewController &&
![self.parentViewController isKindOfClass:UINavigationController.class]) {
return self.parentViewController.ms_navigationBarTopLayoutGuide;
} else {
return self.topLayoutGuide;
}
}
- (id<UILayoutSupport>)ms_navigationBarBottomLayoutGuide {
if (self.parentViewController &&
![self.parentViewController isKindOfClass:UINavigationController.class]) {
return self.parentViewController.ms_navigationBarBottomLayoutGuide;
} else {
return self.bottomLayoutGuide;
}
}
@end
希望这有助于:)
Hope this helps :)
这篇关于topLayoutGuide儿童视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!