Ramotion / animated-tab-bar

:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion
https://www.ramotion.com/animated-tab-bar-ios-app-development-ui-library/
MIT License
11.12k stars 1.33k forks source link

UITabbarItem hidden issue #20

Closed KittenYang closed 8 years ago

KittenYang commented 9 years ago

When I pushed from a VC to anothor VC,I want to hide the tabbar. So what I do first is set the "Hide Bottom Bar on Push" in the Storyboard ,the result is the tabbar is hidden indeed but the UITabbarItems are still.I also use UIVIew.animateWIthDurarion() to hide the tabbar but also failed.What can I do to hide the tabbar and the tabbaritem?

megatyx commented 9 years ago

I'm having the same problem. I can hide the bar itself, but the icons stay. I've even tried to individually hide and disable the icons, but I was unsuccessful. I really want to use it, but I can't until this is solved.

KittenYang commented 9 years ago

@megatyx Lastly ,I give up and use the original tabbar. Sigh~

PatientLiu commented 9 years ago

Create a new class import UIKit

extension RAMAnimatedTabBarController:UINavigationControllerDelegate{ func hideTabBar(flag:Bool) { let atc = self let icons = atc.iconsView

    if (flag == true ) {

        for icon in icons {
            icon.icon.superview?.hidden = true
        }
        atc.tabBar.hidden = true

    } else {
        atc.tabBar.hidden = false
        for icon in icons {
            if let sup = icon.icon.superview{
                sup.hidden = false
                sup.superview?.bringSubviewToFront(sup)
            }
        }
    }
}

func navigationController(navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool){
    hideTabBar(viewController.hidesBottomBarWhenPushed)
}

}

in RAMAnimatedTabBarController.swift viewDidLoad let conls = (self.viewControllers as? [UIViewController])?.filter({$0 is UINavigationController}) ?? [] for ctl in conls{ (ctl as! UINavigationController).delegate = self } Because I was so mixed before the OC will also cover the situation tabbar icon So you must remember to call self.hidesBottomBarWhenPushed = YES you want to hide tabbar of oc interface ; Remember not generate Bridging-Header directly call self.hidesBottomBarWhenPushed = YES;

PatientLiu commented 9 years ago
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
    hideTabBar(viewController.hidesBottomBarWhenPushed)
}

self.tabBarController.tabBar.hidden = YES;
self.hidesBottomBarWhenPushed = YES;

Join these can be synchronized to hide tabbar not have to hide when we jump

andersonsoares commented 9 years ago

Thanks @LiuHengChina , very well done :)

markotl88 commented 9 years ago

Hello guys, I'm having similar problems hiding TabBar. This solution works for me too, but I'm just wondering is it possible to add some animation when BottomBarr hides?

markotl88 commented 9 years ago

I also tried to hide TabBar on button click (calling setTabBarVisible(!tabBarIsVisible(), animated: true)) with these functions, but that doesn't work like with regular UITabBarController.

func setTabBarVisible(visible: Bool, animated: Bool){
    // bail if the current state matches the desired state
    if (tabBarIsVisible() == visible) { return }

    // get a frame calculation ready
    let frame = self.tabBarController?.tabBar.frame
    let height = frame?.size.height
    let offsetY = (visible ? -height! : height)

    // zero duration means no animation
    let duration:NSTimeInterval = (animated ? 0.3 : 0.0)

    //  animate the tabBar
    if frame != nil {
        UIView.animateWithDuration(duration) {
            self.parentViewController?.tabBarController?.tabBar.frame = CGRectOffset(frame!, 0, offsetY!)
            return
        }
    }
}

func tabBarIsVisible() ->Bool {
    return self.parentViewController?.tabBarController?.tabBar.frame.origin.y < CGRectGetMaxY(self.view.frame)
}
satyamub commented 9 years ago

Can we disable gesture on the tab item to so that we would have a complete full screen view with no impact of TabBarController

ryancstack commented 9 years ago

The proposed solution also doesn't work with interactionTransitions on UINavigationController's swipe back feature. It will instantly pop them up above the from controller. Is there anyway around this?

KittenYang commented 9 years ago

@ryancstack so i just give it up.but honestly it's a really dope animation:P

ryancstack commented 9 years ago

@KittenYang you went back to UITabBarController?

KittenYang commented 9 years ago

@ryancstack yep.

onmyway133 commented 8 years ago

I then use model presentation instead :|

GloomySunday049 commented 8 years ago

i use tabbar' s subviews to get the show Image and label, not to create the constains view if you @LiuHengChina ' methods, when you push a view controller , the constains view will disappear in an instant, we need a duration animation. the code is:

func createCustomIcons() {
        guard (tabBar.items != nil) else {
            fatalError("tabBar.items was nil")
        }

        for item in tabBar.items! as! [TmAnimationTabBarItem] {
            assert(item.image != nil, "add image icon in uitabbaritem")
            var index = 0
            for tabBarButton in tabBar.subviews {
                if let icon = tabBarButton.subviews.first as? UIImageView, let label = tabBarButton.subviews.last as? UILabel {
                    iconsView.append((icon: icon, textLabel: label))
                }
                let tapGesture = UITapGestureRecognizer(target: self, action: "tapHandler:")
                tabBarButton.addGestureRecognizer(tapGesture)
                tabBarButton.tag = index
                index++
            }
        }
    }

and in itemAnimations, use

textLabel.tintColor = textSelectedColor
icon.superview?.superview?.tintColor = iconSelectedColor

not

textLabel.textColor = defaultTextColor
if let iconImage = icon.image {
            let renderImage = iconImage.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
            icon.image = renderImage
            icon.tintColor = defaultTextColor
}

it' s ok to work

0ber commented 8 years ago

added method func animationTabBarHidden(isHidden:Bool) I hope this helps

mhtranbn commented 8 years ago

How i can disable tabbar item?

satyamub commented 8 years ago

@mhtranbn animationTabBarHidden(true)

mhtranbn commented 8 years ago

Thanks @satyamub When the first launch tabbar. I want change color of tabbar item. not hiddent. https://lh3.googleusercontent.com/stTiAxzpyFVyJgyqMAzh59zTRUJIiUl8UsAHpNOxlTfVVHvj-lSTq1Uy1y2ZbhpwPVF1CIfr5c2ZrwaeNtrQ1JmSK1Rwo55K_UvPr2InfHvgb3o9sxKdhxaKWAFxPXM477w5AxtOBs-Gl7ZWeX2S2feDkwK1XESeDwkoUzfWSZtf0HVh60CinDodJnH6HglHkmieYH3NU0tZIxtECU-tS-0TQS8RLkhn-uUCFONw-E2GXV9j4415XB4eKTtCtr9jVMGeKFnMZzD44jjg4VcwDD5b0L7AAN9T6hTVHzCWISPB9cYbaiVQ7iuBSZtJN0PbEBILo0G-QKDzs6KX-2QxIAUX7wxNWjsZjKUC-M-6EdvxrMjppLZmtlgbbdnPXIHgEg9kEuhIxBCkxW_mK051CNR5mbDEJIYC4JbG7Nub0oW2xtfhkMiWxl6wW_aA2iKfX9Y4jqfkGnet0O2qn2W6OF3e_kRBnJXiSybh-V2FfKRbSAzQr8YhUuM83SvkWWBLoMcoxKa-x5bEmFaAUP5LcemEBpwo9NRFhOFGkR-CmDczBAklvOv6j4CC7i9H7PyM_31evKMaQhZLqluv76ScZhlojZ2dHSUE=w151-h61-no

jeffreyabarrios commented 8 years ago

when executing animationTabBarHidden()true, it fails to add the tabbar.items to guard let item. Displays the error "add tabbar items"

pnaqash commented 7 years ago

When i change the tab bar selected index (click on button on uiviewcontroller screen not in tabbar) then page change but select icon not change in tab bar self.tabbarcontroller!.selectedIndex = 2

hammadzz commented 7 years ago

Nobody should use this library. Hiding the tab bar is basic functionality of the standard tab bar. This is just poor design. I am going to remove this library from my project. Just not worth it at all.

omarshamali commented 6 years ago

@hammadzz me too, spent much time for such poor library

Erik262 commented 6 years ago

Maybe it is not really a good code design, but I solved the hide problem like this:

let animatedTabBar = tabBarController as? RAMAnimatedTabBarController animatedTabBar?.animationTabBarHidden(true)