• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - ICViewPager 顶部和底部的奇怪空间

[复制链接]
菜鸟教程小白 发表于 2022-12-12 09:30:57 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我使用 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap