Navigation bar appear on click on view
Asked Answered
L

6

8

I attach the video of my issue. When i click on anywhere in viewcontroller navigation bar is appear

override func viewWillAppear(_ animated: Bool) {
    self.navigationController?.setNavigationBarHidden(true, animated: true)
    self.navigationController?.isNavigationBarHidden = true
    self.navigationController?.hidesBarsOnTap = true
}

The above code added on viewwillappear its working on initially but when I click anywhere on screen navigationbar is appear.

Locke answered 25/1, 2020 at 8:19 Comment(11)
Are you using SceneDelegate?Hallowed
This project created in xcode 10Locke
Can you show me your AppDelegate, where you have defined your NavigationController?Hallowed
let storyboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil) let navigationController:UINavigationController = storyboard.instantiateInitialViewController() as! UINavigationController let rootViewController:UIViewController = storyboard.instantiateViewController(withIdentifier: "NexaRootSideMenuViewController") as! NexaRootSideMenuViewController navigationController.viewControllers = [rootViewController] navigationController.isNavigationBarHidden = true appdelegate.window?.rootViewController = navigationControllerLocke
Try this: navigationController.setNavigationBarHidden(true, animated: false)Hallowed
I also try with this code not working.Locke
Did you write anything regarding navigation except viewDidLoad(), viewWillAppear() or viewDidAppear(). Please check it by mistake written then find it.Napier
The video shows the actual navigation-bar appearing. But the view-controller appears to have a "navigation-bar" with back button setup. Is this a custom view-controller with a custom navigation setup? On tap making the navigation-bar appear must be declared and defined intended... this is no iOS behaviour. Please take a look at the code embedding/ presenting the view-controller. There must be a gesture-/ touch- handler showing and hiding the navigation-bar on tap. Tip: if you share code, please update the question, reading code snippets from the comments is hard.Ensoll
I update my answer @EelcoKoelewijn please check it. I create custom navigation controller and hide system navigation controller but after few screen transaction navigation bar appear automatically.Locke
self.navigationController?.hidesBarsOnTap = true This causes the navigation bar to show when you tap the content area of the screen. Please have a look at the documentation of the UINavigationController. It states the following: "When the value of this property is true, the navigation controller toggles the hiding and showing of its navigation bar and toolbar in response to an otherwise unhandled tap in the content area."Ensoll
@kishorsoneji self.navigationController?.hidesBarsOnTap = true If you write this then it's going to happen. Is there any specific reason behind adding that?Bolshevist
L
3

Finally this solutions work for me

self.navigationController?.navigationBar.transform = CGAffineTransform(translationX: 0, y: -200)
Locke answered 31/1, 2020 at 3:25 Comment(1)
This is a solution, but what it does is moving the navigation-bar offscreen. The behaviour of showing the navigation-bar on tap is still happening. I would suggest to resolve the real cause and make a proper solution.Ensoll
G
0

Try Below code into ViewController you want to hide NavigationBar

DispatchQueue.main.async {
    self.navigationController?.setNavigationBarHidden(true, animated: false)
    self.view.isUserInteractionEnabled = true
    //Below code conflicts with the hidden `NavigationBar` and make it visible on tap so set it false as below
    self.navigationController?.hidesBarsOnTap = false
}

And ADD Below code in Other ViewController you want to show Navigationbar (Not in every other ViewController , just in ViewController you push or pop from thisViewController)

self.navigationController?.setNavigationBarHidden(false, animated: true)
Gerund answered 28/1, 2020 at 12:35 Comment(1)
No sir, When I tap on screen that time navigation is appear please see video carefullyLocke
G
0

Try with global queue

DispatchQueue.global().async {
     navigationController?.setNavigationBarHidden(true, animated: animated)
}

or simple add this code in viewDidAppear

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    navigationController?.setNavigationBarHidden(true, animated: animated)
}

if this two won't work then check your view tap event may be there is some code added for navigation

Gown answered 28/1, 2020 at 12:48 Comment(6)
No sir, When I tap on screen that time navigation is appear please see video carefullyLocke
I saw that there may be some event is fired on view tap. disable user interaction of view: self.view.isUserInteractionEnabled = false. and try to tap on your screen still navigation is appear on not?Sternforemost
No any event fire on Tap @NøBi MacLocke
Have you disabled user interaction on you screen?Sternforemost
When you disbale superview user interaction disable automatically child view user interaction is disable.Locke
Yes i knew that, but check it if interaction of view is disabled at that time this navigation is appearing or not.Sternforemost
S
0

Check out your main UINavigationController storyboard properties in storyboard and uncheck the "Hide bars when vertically compact", "Hide bars on tap". this causes the navigation bar to appear when click on view.

if you are creating UINavigationController programmatically then use following code.

UINavigationController().hidesBarsWhenVerticallyCompact = false
UINavigationController().hidesBarsOnTap = false

enter image description here

Sarcophagus answered 30/1, 2020 at 10:52 Comment(4)
change this in your viewWillAppear " navigationController?.hidesBarsOnTap = false " and i've edited my above answer and try, mainly uncheck all options under "Hide Bars section in storyboard"Circumscissile
override func viewWillAppear(_ animated: Bool) { self.navigationController?.setNavigationBarHidden(true, animated: true) self.navigationController?.isNavigationBarHidden = true self.navigationController?.hidesBarsOnTap = false }Circumscissile
Please check my video. View is already appear but issue is after few movement user click on view navigation is appear @Sam'sHell811Locke
i've seen your video, Did you try above step this will solve your problem i've created same scenario if anyone check Hide bars "On tap" and "When vertically compact" then this issue occur so uncheck it in storyboard or change both properties to false programmatically as i've seen in your above code you've used hidesBarOnTap = true which is creating the problem so make it false.Circumscissile
P
0

TRY TO BELOW

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    navigationController?.isNavigationBarHidden = true
}

override func viewWillDisappear(_: Bool) {
    super.viewWillDisappear(true)
    navigationItem.title = ""
}
Public answered 31/1, 2020 at 20:21 Comment(2)
check this solution. @kishor-sonejiPublic
Please check the video @Public Initially navigation bar is hide when I click on window that time navigation is appear.Locke
S
0

I had a same problem too.Storyboard I deleted and recreated the viewController and it was fixed. For this reason I think the problem is related to the viewController not related to the NavigationController. I suggest you delete and recreate the viewController.

Spur answered 23/2, 2021 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.