菜鸟教程小白 发表于 2022-12-12 09:30:57

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


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

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

<blockquote>
<p>UITabbarController --&gt; UINavigationController --&gt; TabVC (which contains ICViewPager) --&gt; Content views: Content1VC, Content2VC, Content3VC</p>
</blockquote>

<p>这是 <code>TabVC</code> 中的代码(配置为具有 <code><ViewPagerDataSource, ViewPagerDelegate></code>):</p>

<pre><code>// in viewDidLoad
self.dataSource = self;
self.delegate = self;
self.edgesForExtendedLayout = UIRectEdgeNone;
</code></pre>

<p>对于委托(delegate)方法:</p>

<pre><code>#pragma mark - ViewPagerDataSource
- (NSUInteger)numberOfTabsForViewPager:(ViewPagerController *)viewPager {
    return tabsContents.count;
}

- (UIView *)viewPager:(ViewPagerController *)viewPager viewForTabAtIndex:(NSUInteger)index {

    UILabel *label = ;
    label.text = ;
    label.textColor = ;
    ;

    return label;
}

- (UIViewController *)viewPager:(ViewPagerController *)viewPager contentViewControllerForTabAtIndex:(NSUInteger)index {
    UIViewController *vc = ];
    return vc;
}
</code></pre>

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

<p>注意:这仅在 <strong></strong>View 从推送的 ViewController 中弹出,或更改 <code>UITabbarController</code></p> 中的选项卡后才会出现

<p> <a href="/image/09e2y.png" rel="noreferrer noopener nofollow"><img src="/image/09e2y.png" alt="Screenshot"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我认为是 <code>automaticallyAdjustsScrollViewInsets</code> 和 <code>edgesForExtendedLayout</code> 之间的冲突。</p>
<p>来自 <a href="https://stackoverflow.com/a/19585104/3894781" rel="noreferrer noopener nofollow">this</a>答案:</p>
<blockquote>
<p><strong>edgesForExtendedLayout</strong></p>
<p>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.</p>
</blockquote>
<p>和</p>
<blockquote>
<p><strong>automaticallyAdjustsScrollViewInsets</strong></p>
<p>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&#39;t work because your table will start scrolling where the navigation bar ends and it wont go behind it.</p>
</blockquote>
<p>因此,<code>automaticallyAdjustsScrollViewInsets</code> 默认为 YES,因此在顶部插入一个正插图,等于导航栏的高度。现在,当您应用 <code>self.edgesForExtendedLayout = UIRectEdgeNone</code> 时,该插图会从导航栏下方爬出,从而导致上述问题。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - ICViewPager 顶部和底部的奇怪空间,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/33338487/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/33338487/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - ICViewPager 顶部和底部的奇怪空间