菜鸟教程小白 发表于 2022-12-12 17:51:17

ios - 在导航 Controller 中导航时如何保持滚动位置?


                                            <p><p>一直在环顾四周,但我没有找到对我有帮助的答案。我想知道当我在导航 Controller 中向前和向后移动时如何将滚动位置保持在 ScrollView 中。目前,当我转到导航 Controller 中的另一个 View 时, ScrollView 会重置并在我返回时位于顶部。任何代码将不胜感激。对不起,如果我的解释不够好。到目前为止,这就是我所拥有的,我知道这行不通,但我该怎么办?</p>

<pre><code>- (void)viewWillAppear:(BOOL)animated {
    scrollView.contentOffset.y = scrollSave;
    ;
}

- (void)viewWillDisappear:(BOOL)animated {
    CGFloat scrollSave = scrollView.contentOffset.y;
    ;
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您上面的代码甚至不应该编译。您可以将此滚动位置保存在另一个变量中,但通常滚动位置不应自行重置。您应该完全删除任何试图操纵内容偏移的代码,并查看它是否在返回 View 时将其恢复到正确的滚动位置。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在导航 Controller 中导航时如何保持滚动位置?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/20910271/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/20910271/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在导航 Controller 中导航时如何保持滚动位置?