簡體   English   中英

TapGesture在tabBar下不起作用

[英]TapGesture doesn't work under tabBar

我有一個帶有3個ViewController的“經典應用”和一個用於更改ViewController的tabBar。

在我的第一個ViewController上,我有一個在所有屏幕上都顯示UIView的按鈕,因此我使用setTabBarVisible函數隱藏了tabBar:

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
}
}

可以了,tabBar被隱藏了,我看到了所有的UIVIew。 問題是,我在UIView的底部有一個UILabel(在我通常顯示tabBar的位置),並且我無法在UILabel上使用TapGesture,所以什么也沒發生。 (如果我在其他地方顯示標簽,則UITapGesture效果很好。)

我試圖將我的tabBar的zPosition設置為0,將UIView的zPosition設置為1,但這也不起作用。

如何在視圖底部使標簽可點擊?

確保是真的

label.isUserInteractionEnabled = true

請參考此鏈接可能對您有幫助。

檢查UILabel.isUserInterration =啟用

確保隱藏標簽欄時,取消選擇“垂直視圖控制器在底部欄下”屬性。 參見atteh imnage。

您可以通過編程方式嘗試

ViewController.edgesForExtendedLayout = UIRectEdge.top

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM