【问题标题】:TabBarController adding custom button not clickable issue [duplicate]TabBarController 添加自定义按钮不可点击问题[重复]
【发布时间】:2017-08-25 12:41:29
【问题描述】:

我在 tabBarController 上添加了一个自定义按钮,当我在 tabBarController 内点击它时,该按钮变成了 tabBarController > 它工作正常,但如果我点击 标签栏 之外的部分,则无法点击。

class CustomBar: UITabBarController, UITabBarControllerDelegate {

    func addButton() {

        mainBasketView.frame =  CGRect(x: self.view.frame.size.width / 2 - 30, y: -20, width: 58, height: 58)
        mainBasketView.basketButton.addTarget(self, action: #selector(self.btnNewMoment_Action), for: UIControlEvents.touchUpInside)
        tabBar.addSubview(mainBasketView)
    }
}

我不想将其添加为 view.addSubView,因为当我调用 hidesBottomBarWhenPushed 时视图不会消失

【问题讨论】:

  • 遇到同样的问题...你找到解决办法了吗??

标签: ios swift uitabbarcontroller uitabbar


【解决方案1】:

你应该将你的标签高度增加到默认的 49 并且你的按钮是 58

extension UITabBar {
        override open func sizeThatFits(_ size: CGSize) -> CGSize {
            return CGSize(width: UIScreen.main.bounds.width, height: 60)
        }
    }

【讨论】:

  • 感谢您的回复,但我想保留那个看起来在标签栏之外的设计。不可能吗?
  • 在这个答案中,我发现人们抱怨 hidesBottomBarWhenPushed 不会删除中心的按钮。我做了一个显示相同问题的测试项目。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-22
相关资源
最近更新 更多