【发布时间】:2020-06-23 14:26:55
【问题描述】:
当我点击标签栏中的标签时,我想滚动到我的 tableView 的顶部并在navigationBar 中显示largeTitle。
使用scrollToRow方法不显示大标题:
extension TableViewConstroller: UITabBarControllerDelegate {
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if tabBarController.selectedIndex == 1 {
let indexPath = IndexPath(row: 0, section: 0)
tableView.scrollToRow(at: indexPath, at: .top, animated: true)
}
}
}
我也试过
self.tableView.scrollRectToVisible(CGRect(x: 0, y: -64, width: 1, height: 1), animated: true)
这有时有效,但如果我向下滚动 tableView,当此方法向上滚动时,navigationBar 仍会折叠。
如何模仿 tableView 的 scrollsToTop 属性的行为,该属性滚动到顶部并显示 largeTitle?它的动画非常流畅,并且总是显示较大的navigationBar。
【问题讨论】:
-
您为您的
navigationBar设置了prefersLargeTitles吗? -
@koen 是的,prefersLargeTitle 已设置。
-
@SidShehxad 这个问题是基于 scrollView,我有一个 tableView
-
@WalterBeiter
UITableView是UIScrollView的子类,因此它很可能适用。
标签: ios swift uitableview uinavigationbar large-title