[ad_1]
I’ve carried out a characteristic, while you press on a UITabBar icon and viewController1 scrolls up utilizing its UIScrollView. It really works completely, but when I scroll view down and cease someplace, then swap to a different viewController2, then get again to viewController1 and press tabBar icon – the viewController1 will scroll up, however Massive Title won’t ever be confirmed, and I ought to press tabBar icon yet one more time to point out it:
The code I exploit for scroll up the VC1:
non-public var biggestTopSafeAreaInset: CGFloat = 0
override func viewSafeAreaInsetsDidChange() {
tremendous.viewSafeAreaInsetsDidChange()
self.biggestTopSafeAreaInset = max(view.safeAreaInsets.prime, 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(the place: { $0 is UIScrollView }) as? UIScrollView else { return }
if traitCollection.verticalSizeClass == .compact {
scrollView.setContentOffset(CGPoint(x: 0, y: -view.safeAreaInsets.prime, animated: true)
} else {
scrollView.setContentOffset(CGPoint(x: 0, y: -biggestTopSafeAreaInset, animated: true)
}
}
}
I attempted to trace biggestTopSafeAreaInset in several levels of VC1 life, nevertheless it all the time has the identical quantity – 196.0. However then why it does not scroll until the Massive Title after viewControllers swap?
[ad_2]
