使用preferredsLargeTitles和UITableView平滑滚动 [英] Smooth scrolling with prefersLargeTitles and UITableView

查看:60
本文介绍了使用preferredsLargeTitles和UITableView平滑滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 prefersLargeTitles 并添加 UITableView 时,滚动遇到了问题.

I encountered a problem with the scrolling when using the prefersLargeTitles and added UITableView.

如果我在导航控制器中设置了 prefersLargeTitles ,并且其根是 UITableViewController ,那么一切都很好,滚动导航大标题的工作方式与我们在系统应用程序(在iOS 11+中).

If I set the prefersLargeTitles within a navigation controller and its root is a UITableViewController everything is fine, scrolling of the navigation large title works the same way we can see in the system apps (in iOS 11+).

但是,如果我使用 UIViewController 并在其中添加 UITableView ,则滚动似乎会有所不同.导航栏的移动速度比我实际滚动的速度更快.每当我滚动到一个会触发该标题的位置时,它就只会隐藏/显示大标题,因此最终我会得到完全不同的感觉.

However, if I use a UIViewController and add a UITableView in it, scroll seems to act differently. Navigation bar is moving more/faster than I actually scroll. It just hides/shows the large title whenever I scroll into a position that just triggers it, so I end up with the totally different feeling.

推荐答案

原来是布局导致了此问题.

Turns out that the layout is causing this problem.

如果 UITableView 使用顶部对齐至:安全区域约束(除了底部,在 Safe Area之前,并在其末尾),并且未在栏下扩展.

The problem occurs if the UITableView use Align top to: Safe Area constraint (besides the bottom, leading and trailing to Safe Area) and is not extended under the bar.

但是,如果我使用扩展的布局,将顶部与 superview 对齐,我仍然可以使用 UITableView 并获得大标题及其导航栏的正确行为

However if I use the extended layout, align top to the superview, I can still use the UITableView and get the correct behaviour of the large title and its navigation bar.

edgesForExtendedLayout = .top
extendedLayoutIncludesOpaqueBars = true

或使用导航栏的 isTranslucent = true 对其进行扩展.

Or use navigation bar's isTranslucent = true which extends it too.

这篇关于使用preferredsLargeTitles和UITableView平滑滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆