uinavigationbar大标题当滚动查看时不会出现
我已经实现了一个功能,当您按 uitabbar
图标和 view controller1
使用其 uiscrollview
滚动时。它可以很好地工作,但是如果我滚动查看
向下并停止某个地方,然后切换到另一个 view controller2
,然后返回到 view> view> view controller1
,然后按 tabbar
图标 - viewController1
将滚动,但是大标题
将永远不会显示,我应该按 tabbar
iCON一个更多时间显示它:
我用于滚动VC1的代码:
private var biggestTopSafeAreaInset: CGFloat = 0
override func viewSafeAreaInsetsDidChange() {
super.viewSafeAreaInsetsDidChange()
self.biggestTopSafeAreaInset = max(view.safeAreaInsets.top, biggestTopSafeAreaInset)
}
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if tabBarController.selectedIndex == 0 {
let navigationVC = viewController as? UINavigationController
let firstVC = navigationVC?.viewControllers.first as? CurrencyViewController
guard let scrollView = firstVC?.view.subviews.first(where: { $0 is UIScrollView }) as? UIScrollView else { return }
if traitCollection.verticalSizeClass == .compact {
scrollView.setContentOffset(CGPoint(x: 0, y: -view.safeAreaInsets.top, animated: true)
} else {
scrollView.setContentOffset(CGPoint(x: 0, y: -biggestTopSafeAreaInset, animated: true)
}
}
}
我尝试在 vc1
life的不同阶段跟踪 bigaltopsafeareainset
,但它始终具有相同的数字 - 196.0。但是,为什么它不会滚动,直到大标题
在ViewControllers Switch之后?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的表观视图中,将ContentInsetAdjustmentBehavior在Controller中不在
控制器中,再次更新导航栏UI
,这是导航控制器
,这是Tabbar Controller
in your tableView set contentInsetAdjustmentBehavior to never
in controller update the ui of navigation bar again
here is the navigation controller
here is the Tabbar Controller
尝试在ViewDidload中添加此内容:
此单行块大标题导航栏...我不知道为什么,但是此技巧会暂时解决问题...
Try to add this in viewDidLoad:
this single line block large title navigation Bar... I don't Know why, but this trick fix momentarily the issue...
经过一番研究,我发现什么可以解决我的问题。如果您以
TABBARCONTROLLER didSelect
的少量延迟调用此方法,则可以在切换ViewControllers后看到一个大标题。但是我仍然无法确切地弄清楚为什么会发生...After some research I found out what can fix my problem. If you call this method with a small delay in
tabBarController didSelect
then it will be possible to see a Large Title after switching viewControllers. But I still can't figure out exactly why it happened...