I have a special question and I doesn't find an answer for my case. I have an embedded ViewController in a navigation controller with a Container View. In this Container View is a scrollView. What I want to do is: When I scroll in my ContainerView down I want that the Bar Button Item in the NavigationContoller from my ViewController disappear. When I scroll up it should appear again.
I can hide the whole NavigationBar with the following code, which is in the ContainerViewController.swift-file:
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
print("123")
if(velocity.y>0) {
UIView.animate(withDuration: 0.5, delay: 0, options: UIView.AnimationOptions(), animations: {
self.navigationController?.setNavigationBarHidden(true, animated: true)
print("Hide")
}, completion: nil)
} else {
UIView.animate(withDuration: 0.5, delay: 0, options: UIView.AnimationOptions(), animations: {
self.navigationController?.setNavigationBarHidden(false, animated: true)
print("Unhide")
}, completion: nil)
}
}
Is there a similar code that only makes the bar button item disappear? I don't know how to access the bar button item because I can't connect it as an Outlet to the ContainerViewController.swift-file but only to the ViewController.swift-file.
I hope you understand my question and can answer it.