I need to sync the vertical content offset for a tabBbar viewControllers. I accomplished this sending a notification on didScroll
func scrollViewDidScroll(_ scrollView: UIScrollView) {
NotificationCenter.default.post(name: name, object: self, userInfo: ["offset": scrollView.contentOffset])
}
And the reading it back in viewDidLoad:
NotificationCenter.default.addObserver(forName: name, object: nil, queue: .main) { notification in
let offset = notification.userInfo!["offset"]! as! CGPoint
if let sender = notification.object as? SyncedViewController, sender != self {
self.collectionView.contentOffset = offset
}
}
Everything works as expected expect one big caveat, you need to tap on each tab in order this to work, otherwise it wont work 🙁
I also tried to force viewDidLoad using _ = vc.view
but with no success.