gpt4 book ai didi

ios - subview Controller 中的 topLayoutGuide

转载 作者:IT王子 更新时间:2023-10-29 07:32:26 26 4
gpt4 key购买 nike

我有一个带有半透明状态栏和导航栏的 UIPageViewController。正如预期的那样,它的 topLayoutGuide 是 64 像素。

但是,UIPageViewController 的 subview Controller 报告 topLayoutGuide 为 0 像素,即使它们显示在状态栏和导航栏下方也是如此。

这是预期的行为吗?如果是这样,将 subview Controller 的 View 放置在真实 topLayoutGuide 下的最佳方法是什么?

(没有使用 parentViewController.topLayoutGuide,我认为这是 hack)

最佳答案

同时 this answer可能是正确的,我仍然发现自己必须遍历包含树才能找到正确的父 View Controller 并获得您描述的“真正的 topLayoutGuide”。这样我就可以手动实现 automaticallyAdjustsScrollViewInsets

我是这样做的:

在我的 TableView Controller (实际上是 UIViewController 的子类)中,我有这个:

- (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 中的类别方法,我是这样实现它们的:

@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

希望这有帮助:)

关于ios - subview Controller 中的 topLayoutGuide,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19140530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com