UITabbarController 配下の UINavigationController をモーダル表示する


tabBarController デリゲートメソッドの shouldSelect viewController 内でNavigationController をインスタンス化してプレゼントします。

StoryBoard から TabBarItem に タグをつけることをお忘れなく。

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
    guard viewController is UINavigationController else { return true }
    if tabBarController.selectedIndex == 1 {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let popupViewController = storyboard.instantiateViewController(withIdentifier: "NavigationController") as! UINavigationController
        popupViewController.modalPresentationStyle = .fullScreen
        tabBarController.present(popupViewController, animated: true, completion: nil)
        return false
    } else {
        return true
    }
}

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
[email protected]

Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。

Twitter
Medium