私は現在、建物だアプリでも似たような実装しなければならなかったが、それは比較的です直接行うには、これを実現するために、UITabBarController
のデリゲートメソッドを実装する必要があります。
あなたが実装する必要がデリゲートメソッドは次のとおりです。このメソッドからfalseを返す tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool
があなたのタブを選択すると、タブコントローラを停止します、あなたは、単にプログラム的UIViewController
を提示するために、独自のロジックを実装する必要があります。私の実装が多少異なり、より多くの変数を持っているとして、私は上記のコードをテストしていませんでした
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
// If your view controller is emedded in a UINavigationController you will need to check if it's a UINavigationController and check that the root view controller is your desired controller (or subclass the navigation controller)
if viewController is YourViewControllerClass {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let controller = storyboard.instantiateViewController(withIdentifier: "storyboardID") as? YourViewControllerClass {
controller.modalPresentationStyle = .fullScreen
self.present(controller, animated: true, completion: nil)
}
return false
}
// Tells the tab bar to select other view controller as normal
return true
}
:
は、ここでの例です。一般的な原則は同じです。
どのように乗り遅れているか教えてください。必要に応じて回答を更新します。
私はあなたのコードを使用しましたが、それはそれが動作するようにどのように動作していません。そこで、私のTabBarControllerのための新しいクラスを作成し、あなたのコードをそこに貼り付けました。それはあなたの意味ですか?そして、どのクラスをYourViewControllerClassの代わりに書くべきですか?多分私の元の投稿にリンクしている私の写真を見ることができます。 –
ねえ、あなたは 'UITabBarController'をサブクラス化し、このクラスに' UITabBarDelegate'を実装する必要があります。 'viewDidLoad'では、' self.delegate = self'を実行する必要があります。そして、下のタブを選択しようとすると、上記のメソッドが起動します。 'YourViewControllerClass'は、あなたのストーリーボードのビューコントローラ(左のもの)に関連付けられたクラスです。 'UIViewController'をサブクラス化し、このクラスをそのView Controllerに適用する必要があります。 – WsCandy
Yeey!できます。あなたの助けに感謝します。私はself.delegate = selfを忘れていました。今私がボタンでそれを閉じたい場合は、どのようにViewControllerに戻ることができますか? –