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?
Related
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
}
}
I have a ViewController (LandingViewController) and one drawerViewController.
I am using SWRevealViewController and I added a gesture to Landing view but when it will open the DrawerViewController then it is covering status bar only once. I don't know why this is happening, But it is hiding once and after that working fine.
I am not using NavigationBar and I have a map view in my LandingViewController.
I have drawer button in my LandingViewController.
If I will open or reveal the view by button it's working fine. But if I will open it by view it is hiding status bar.
Here below is my code :-
btnDrawerMenu.addTarget(self.revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:)), for: UIControlEvents.touchUpInside).
//Reveal View Drawer menu
fileprivate func createReveal() {
if self.revealViewController() != nil {
self.revealViewController().rearViewRevealWidth = self.view.frame.width - 20
self.revealViewController().rearViewRevealOverdraw = 0.0
self.revealViewController().bounceBackOnOverdraw = false
self.revealViewController().bounceBackOnLeftOverdraw = false
self.revealViewController().toggleAnimationType = .easeOut
}
}
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)
}
}
I have a UIViewController that is presented in two ways, either modally or pushed on top of a navigation controller stack. The UIViewController contains a UITableView and a UIToolbar. When presented modally, i needed a way of showing a title for the ViewController, so I added in another UIToolbar, topToolbar. My problem is, whenever I push the UIViewController, I don't need topToolbar anymore, since the navigation tabbar already shows the title. When I set topToolbar's hidden property to true, however, my UITableView is not bound to the bottom of the navigation tab bar and there's space between the UITableView and the navigation tabbar, which doesn't look so good. I tried to call removeFromSuperview() on topToolbar instead of setting its hidden property to true, but that didn't work out, and topToolbar appeared under the navigation bar, and now i have two titles instead of one. Any idea on how this can be done? I can't add pictures, but here's my code for manipulating the appearance of the UIViewController based on whether it's presented modally or pushed on top of the navigation stack:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if itemBought != nil {
cart.items.append(itemBought!)
}
totalView.layer.borderColor = UIColor.grayColor().CGColor
totalView.layer.borderWidth = 0.5
totalLabel.text = "$" + String(format: "%.2f", cart.getTotal())
if let navBar = self.navigationController?.navigationBar {
//hide toolbar and tabbar
topToolbar.removeFromSuperview()
self.tabBarController?.tabBar.hidden = true
//hide shop button
var bottomItems: [UIBarButtonItem] = bottomToolbar.items as! [UIBarButtonItem]
if let index = find(bottomItems, shopToolbarButton) {
bottomItems.removeAtIndex(index)
}
bottomToolbar.items = bottomItems
}
}
I should also mention that i have a constraint on the UITableView that's basically: distance between UItableView.top and Top Layout Guide.Bottom is <= to the height of topToolbar, which is 44.
Any ideas?
When you present the View Controller modally, why not put it in a UINavigation Controller?
let navigationController = UINavigationController(rootViewController: myViewControllerInstance)
self.navigationController?.presentViewController(navigationController, animated: true, completion: { () -> Void in
//do something here when animation is complete if you want
})
I have the hidesBottomBarWhenPushed = true set for one of my UIViewController's (call it ViewControllerA) that is pushed onto my UINavigationController stack. I also opt to show the bottomBar when I push a new ViewController ontop of ViewControllerA. Therefore I have:
class ViewControllerA: UIViewController {
override func viewWillDisappear(animated: Bool) {
self.hidesBottomBarWhenPushed = false
}
override func viewWillAppear(animated: Bool) {
self.hidesBottomBarWhenPushed = true
}
This all works fine.
When I push ViewControllerA, the bottom bar hides.
When I push any other ViewController, the bottom bar shows.
However, when I am traveling backwards in the navigation stack (aka hitting the UIBarButtonItemBack button), I cannot get the bottomBar to hide when I pop the navigation stack to reveal ViewControllerA.
What am I missing? Thanks!
Got it! Here's what worked:
class ViewControllerCustom: UIViewController {
init() {
self.hidesBottomBarWhenPushed = true
}
override func viewDidAppear(animated: Bool) {
self.hidesBottomBarWhenPushed = false
}
}
And then in every UIViewController's custom implementation of BarButtonItemBack pressed I check to see if the previous view controller (that will be popped to needs to hide the tab bar). Granted I abstracted this out into a general function so I didn't need to repeat code, but here's the concept. Thanks for the help figuring this out though!
func barButtonItemBackPressed(button: UIButton) {
var viewControllers = self.navigationController!.viewControllers as! [UIViewController]
if ((viewControllers[viewControllers.count - 2]).isKindOfClass(ViewControllerCustom.self)) {
(viewControllers[viewControllers.count - 2] as! ViewControllerCustom).hidesBottomBarWhenPushed = true
}
self.navigationController?.popViewControllerAnimated(true)
}
I believe the intended use of this property is to hide the bar when pushed. So, when your view controller appears after the top-most one is popped, it wasn't pushed on the stack, so it doesn't change the tab bar's appearance.
This leaves you with two options:
1) Keep the bottom bar for all view controllers. When text is being entered, the keyboard covers the bottom bar.
2) Hide the bottom bar for View Controller A, as well as any other view controller that is pushed on top of A.