导航栏大标题过渡代表
Navigation Bar Large Title transition delegate
我在导航栏中启用了 Large Title
自动 Display Mode
,以便在用户滚动时缩小。有没有办法在这种转变发生时得到通知?我没有为此找到任何委托方法。我有一个带有长标签的 Right Bar Button Item
,我想在大标题缩小时将其隐藏,以便标题完全居中。
显然没有任何代表或任何其他官方方式可以通知这件事。所以我的解决方法是使用 ScrollViewDelegate
:
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let height = navigationController?.navigationBar.frame.size.height, height == 44 {
// handle small title
}
else {
// handle large title
}
}
}
这在 iPad 上不起作用,因为导航栏的高度不同,但这是我的情况。
另外请记住,scrollViewDidScroll
为单个小卷轴调用了 XX 次,因此在进行任何更新之前,请检查它们是否已经完成。
我在导航栏中启用了 Large Title
自动 Display Mode
,以便在用户滚动时缩小。有没有办法在这种转变发生时得到通知?我没有为此找到任何委托方法。我有一个带有长标签的 Right Bar Button Item
,我想在大标题缩小时将其隐藏,以便标题完全居中。
显然没有任何代表或任何其他官方方式可以通知这件事。所以我的解决方法是使用 ScrollViewDelegate
:
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let height = navigationController?.navigationBar.frame.size.height, height == 44 {
// handle small title
}
else {
// handle large title
}
}
}
这在 iPad 上不起作用,因为导航栏的高度不同,但这是我的情况。
另外请记住,scrollViewDidScroll
为单个小卷轴调用了 XX 次,因此在进行任何更新之前,请检查它们是否已经完成。