简体   繁体   中英

TapGesture doesn't work under tabBar

I have a "classic app" with 3 ViewController and a tabBar that I use to change ViewController.

On my first ViewController, I have a button that display a UIView on all the screen, so I hide tabBar with this setTabBarVisible func :

extension UIViewController
{

func setTabBarVisible(visible: Bool, animated: Bool)
{
    //* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time

    // bail if the current state matches the desired state
    if (isTabBarVisible == 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: TimeInterval = (animated ? 0.3 : 0.0)

    //  animate the tabBar
    if frame != nil
    {
        UIView.animate(withDuration: duration)
        {
            self.tabBarController?.tabBar.frame = frame!.offsetBy(dx: 0, dy: offsetY!)
            return
        }
    }
}

var isTabBarVisible: Bool
{
    return (self.tabBarController?.tabBar.frame.origin.y ?? 0) < self.view.frame.maxY
}
}

That's working, the tabBar is hidden and I see all my UIVIew. The problem is, I have a UILabel at bottom of the UIView (at the place I usually display the tabBar), and I can't use my TapGesture on my UILabel, nothing is happening. (if I display the label somewhere else the UITapGesture works good.)

I tried to set zPosition of my tabBar to 0 and zPosition of my UIView to 1 but that's doesn't work either.

How can I get my label clickable at bottom of my view?

make sure is true

label.isUserInteractionEnabled = true

Please refer this link may it help you.

Check UILabel.isUserInterration = enable

Make sure that when you hide tabbar, perticular view controller Under bottom bar property is unselect . See atteh imnage.

You can try with programatically also like

ViewController.edgesForExtendedLayout = UIRectEdge.top

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM