I have an app where there is a navigation controller which can have navigation child. I have to put a UIButton where the navigation bar is normally.
The UIButton is connected to targets:
for button in arrayOfButtons {
button.addTarget(self, action: #selector(buttonTouchUpInsideP3), for: [.touchUpInside])
button.addTarget(self, action: #selector(buttonTouchInsideBoundsP3), for: [.touchDown, .touchDragEnter])
button.addTarget(self, action: #selector(buttonDraggedOutOfBoundsP3), for: [.touchDragExit, .touchCancel]) //there is definitly combining that cud be done here...
}
And basically I can't simply hide the navigationBar as I use it for sizing/autolayout, so what I try to do is: (this code is in the ViewDidLoad of the child navigation controller)
self.navigationController?.navigationBar.isUserInteractionEnabled = false
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationItem.hidesBackButton = true
To remove its UI and have it invisible up there, this part works... however, the issue is that I still cannot press anything in the navigationBar area... even though I do isUserInteractionEnabled = false
.
How can I fix this!? So that I can tap a UIButton underneath(?) or rather where the navigationBar is located??
Haven't seen a SO question that has solved this for me :/
Well, for anyone that wants to know:
@StonedStudio was right, I ended up just hiding the navigation bar and instead I simply created a view with the bounds height of the navigationBar anchored to the top of the view.safeAreaLayoutGuide.topAnchor and that way it takes the shape of the would be navigation bar while allowing the tap as well! :)