Hide Bars On Tap with only a bottom toolbar - ios

When you drag a UINavigationController into a storyboard, you can enable the Hide Bars On Tap option which will hide/show the navigation bar and toolbar upon tapping anywhere in the UIView. This works well except in the case where you don't have a navigation bar and you only have a toolbar. (You checked Shows Toolbar but not Shows Navigation Bar.) When you launch the app there is no visible navigation bar but when you tap a navigation bar slides down from the top, then if you tap again both bars slide away.
How can you use Hide Bars On Tap with only a toolbar and prevent a navigation bar from appearing?

You can get hold of the gesture recognizer via the barHideOnTapGestureRecognizer property.Then you add actions to this gestureRecognizer to do whatever you want.
In your case ,this snippet will work:`
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.hidesBarsOnTap = true
navigationController?.barHideOnTapGestureRecognizer.addTarget(self, action: "tap:")}
func tap(gest: UIGestureRecognizer){
navigationController?.navigationBar.hidden = true
}

Related

Swipe back causes navigation bar hides immediately (not smoothly) when the first view controller hides its navigation bar in iOS

I have view controller which navigation bar is hidden.
navigationController?.isNavigationBarHidden = true
I push another controller when tap on a button.
navigationController?.pushViewController(qrGenerateVC, animated: true)
In the second view controller the navigation bar is not hidden.
In other situations when I swipe back the second navigation bar hides smoothly but in this situation It disappear when I start swiping back. so it makes the view look not good.
This is similar to this question which does not have answer. And the view is similar too.
Before swipe screenShot
After swipe screenShot
These images are from that question. but similar thing happens here.
Set this in your second view controller
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.isNavigationBarHidden = false
}

How can I prevent the child view being cut off when I add a tab bar controller?

I want the green view to move forward from the container view as follows.
However, when I add a tab bar controller, the green view is cut off as follows.
I tried the following codes so that the green view is not cut off. But it did not work.
containerView.clipsToBounds = false
containerView.layer.zPosition = 100
self.view.bringSubview(toFront: containerView)
The problem seems to be not in the container view. Because when tab bar controller was added, green view started to be cut off.
When I add a tab bar controller, how can I prevent the green view from being cut off?
The problem is that UITransitionView in your UITabBarController clips all subviews. You can fix this easily if you remove clipsSubview from every subview in your TabBarController. I make this with custom TabBarController. Here is my code
class CustomTabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
for item in self.view.subviews{
item.clipsToBounds = false
}
self.view.clipsToBounds = false
}
}

Navigation bar item as tab bar item

I did search something similar with my question, but didn't find anything to help me solve my issue.
Is it possible to set behavior for navigation bar item as tab bar item?
I use TabBarController. Each tab item should show the corresponding ViewController. When user tap on the item in nav bar it should show the corresponding ViewController too with the bottom tab bar. And this ViewController should be as tab bar controller, but not display tab item in the bottom tab bar.
How I can achieve the scenario describe above? Or any alternative idea how it possible to implement, please! Almost always the top and bottom bars should be visible for each ViewController.
Drag and drop from your bar button item in IB to your class file and define an outlet, then in viewDidLoad create a gesture recognizer, add an action to your gesture recognizer and you are all set. I hope it helps.
class SomeClass: UIViewControler {
let someBarButton:UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(SomeClass.tapFunction))
someBarButton.addGestureRecognizer(tap)
}
func tapFunction() {
//take me to a view controller
self.performSegue(withIdentifier: "myIdentifier", sender: self)
}
}

Center TabBar button going to back

I have created a centre TabBar button by subclassing UITabBarController and adding a bigger button to the centre.
Now when i go to an item in my menu, which is just a static TableViewController embedded in a ViewController the button will not hide with the TabBar, where i have just set the bottom bar to hide on push within interface builder.
Static Table View
Button Still Shown when menu item page loaded. This is just an empty ViewController with a 'show' segue from the static TableViewCell
Hid Bottom Bar Selected.
i also have a problem when going back to the menu and the TabBar is displayed again. The button is now behind the TabBar.
------EDIT-------
I revised my outlook and have added the following to my TabBarController class
override func viewDidLayoutSubviews() {
if self.homeButton != nil {
self.view.bringSubview(toFront: self.homeButton)
for test in self.view.subviews {
if let subView = test as? UITabBar {
if subView.isHidden == true {
self.homeButton.isHidden = true
} else {
self.homeButton.isHidden = false
}
}
}
}
}
its just a little slow, there is a delay of about 1 second from when the view changes to when the button is wither hidden or brought to the front.
Any better ideas about how to display this faster?

iOS UINavigationController barHideOnTapGestureRecognizer and UIButton interference

I have developed an app that makes use of the iOS8 feature to show or hide the navigation bar on a tap of the view.
However, the main view contains a UIButton which also act upon taps. The problem is that both 'objects' are receiving the tap and if I tap the button, the navigation bar toggles its visibility.
I can get to the barHideOnTapGestureRecognizer via the navigation controller but not really sure what can be done with it to stop it responding if a button is tapped.
Is there a way (apart from switching off or changing to 'Swipe to Hide') to subdue the navigation bar's appearance/disappearance when a button is pressed?
Don't use the standard barHideOnTapGestureRecognizer. Fortunately, it's not hard to roll your own:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let gestureRecognizer = UITapGestureRecognizer(target: self, action: "toggleBarsOnTap:")
self.view.addGestureRecognizer(gestureRecognizer)
}
func toggleBarsOnTap(sender: AnyObject?) {
let hidden = !self.navigationBarHidden
self.setNavigationBarHidden(hidden, animated: true)
self.setToolbarHidden(hidden, animated: true)
}
Taps on the view will show/hide the bars, and taps on controls (subviews of the view) will not.
[self.navigationController setNavigationBarHidden:YES];

Resources