2017-08-25 75 views
1

我添加自定義按鈕在tabBarController和按鈕變成在tabBarController被點擊時,我打它裏面的tabBarController它工作正常,但如果我擊中tabar以外的部分,不可點擊。TabBarController添加自定義按鈕無法點擊的問題

enter image description here

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

回答

0

你應該增加你的高度塔巴爾其49默認和你的按鈕58

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

感謝您的答覆,但我想保持這種設計看起來使用TabBar之外。不可能嗎? – CAN

+0

所以檢查這個https://stackoverflow.com/questions/36014073/make-custom-button-on-tab-bar-rounded –

+0

在這個答案我發現人們抱怨hidesBottomBarWhenPushed它不會刪除中心的按鈕。我做了一個顯示同樣問題的測試項目。 – CAN