2017-04-08 11 views
3

TabBarの途中にカスタムボタンを持つUITabBarControllerがあります。しかし、私がhidesBottomBarWhenPushed = trueに設定すると、私は奇妙な動作をします。Swift 3でTabBarControllerのカスタムボタンを非表示にする方法は?

enter image description here

私はここでスウィフト3でプログラム

UITabBarControllerを作成したカスタム真ん中のボタンを作成するために私のコードです:

func setupMiddleButton() { 
     let menuButton = UIButton(frame: CGRect(x: 0, y: 0, width: 48, height: 48)) 

     var menuButtonFrame = menuButton.frame 
     menuButtonFrame.origin.y = view.bounds.height - menuButtonFrame.height 
     menuButtonFrame.origin.x = view.bounds.width/2 - menuButtonFrame.size.width/2 
     menuButton.frame = menuButtonFrame 

     menuButton.layer.cornerRadius = menuButtonFrame.height/2 
     view.addSubview(menuButton) 

     menuButton.setImage(UIImage(named: "updatemoment"), for: .normal) 
     menuButton.addTarget(self, action: #selector(menuButtonAction), for: .touchUpInside) 

     view.layoutIfNeeded() 
    } 

func menuButtonAction() { 
    let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let vc: UINavigationController = storyboard.instantiateViewController(withIdentifier: "NewPostID") as! UINavigationController 

    self.present(vc, animated: true, completion: nil) 
    print("segue success") 
} 

それを修正する方法は?真ん中のボタンをBottomBarのままにしておきたい。

ありがとうございます。

答えて

3

Iによりそれを修正することができた:クラスのメニューボタンをインスタンス化

let menuButton = UIButton(frame: CGRect(x: 0, y: 0, width: 64, height: 64)) 

同じコントローラ(TabBarController)中の2つの機能を追加:

func hideTabBar() { 
    self.tabBar.isHidden = true 
    self.menuButton.isHidden = true 
} 

func showTabBar() { 
    self.tabBar.isHidden = false 
    self.menuButton.isHidden = false 
} 

およびtabBarを非表示または表示する必要があるときはいつでも:

let tabBar = self.tabBarController as! InitialViewController 
tabBar.showTabBar() 

現在、一部のコントローラではviewWillAppearおよびviewWillDisearで使用しています。

+0

は魅力的です。どうもありがとうございました。 – Badrinath

関連する問題