OGeek|极客世界-中国程序员成长平台

标题: ios - ICViewPager 顶部和底部的奇怪空间 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:30
标题: ios - ICViewPager 顶部和底部的奇怪空间

我使用 ICViewPager 来创建内容标签。但是,布局看起来很奇怪,因为 ICViewPager 的内容 View 的顶部和底部有奇怪的空间。

如下所示,我在屏幕顶部有一个 UINavigationBar,它是由嵌入 UINavigationController 生成的。然后,UINavigationController 成为UITabbar Controller 中的选项卡之一。这是结构:

UITabbarController --> UINavigationController --> TabVC (which contains ICViewPager) --> Content views: Content1VC, Content2VC, Content3VC

这是 TabVC 中的代码(配置为具有 ):

// in viewDidLoad
self.dataSource = self;
self.delegate = self;
self.edgesForExtendedLayout = UIRectEdgeNone;

对于委托(delegate)方法:

#pragma mark - ViewPagerDataSource
- (NSUInteger)numberOfTabsForViewPagerViewPagerController *)viewPager {
    return tabsContents.count;
}

- (UIView *)viewPagerViewPagerController *)viewPager viewForTabAtIndexNSUInteger)index {

    UILabel *label = [UILabel new];
    label.text = [tabsContents objectAtIndex:index];
    label.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0f];
    [label sizeToFit];

    return label;
}

- (UIViewController *)viewPagerViewPagerController *)viewPager contentViewControllerForTabAtIndexNSUInteger)index {
    UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:[tabsVC objectAtIndex:index]];
    return vc;
}

功能看起来不错,但布局并没有像预期的那样跨越整个空间。红色空格(我将 TabVC View 的背景颜色设置为红色以说明问题)预计不会出现。如何让 ICViewPager 占据红色空间?

注意:这仅在 View 从推送的 View Controller 中弹出,或更改 UITabbarController

中的选项卡后才会出现

Screenshot



Best Answer-推荐答案


我认为是 automaticallyAdjustsScrollViewInsetsedgesForExtendedLayout 之间的冲突。

来自 this答案:

edgesForExtendedLayout

Basically, with this property you set which sides of your view can be extended to cover the whole screen. Imagine that you push a UIViewController into a UINavigationController, when the view of that view controller is laid out, it will start where the navigation bar ends, but this property will set which sides of the view (top, left, bottom, right) can be extended to fill the whole screen.

automaticallyAdjustsScrollViewInsets

This property is used when your view is a UIScrollView or similar, like a UITableView. You want your table to start where the navigation bar ends, because you wont see the whole content if not, but at the same time you want your table to cover the whole screen when scrolling. In that case, setting edgesForExtendedLayout to None won't work because your table will start scrolling where the navigation bar ends and it wont go behind it.

因此,automaticallyAdjustsScrollViewInsets 默认为 YES,因此在顶部插入一个正插图,等于导航栏的高度。现在,当您应用 self.edgesForExtendedLayout = UIRectEdgeNone 时,该插图会从导航栏下方爬出,从而导致上述问题。

关于ios - ICViewPager 顶部和底部的奇怪空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33338487/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4