如何在TabBarController中的所有VC上呈现modalViewController

时间:2017-10-30 00:04:11

标签: ios swift uitabbarcontroller uimodalpresentationstyle

我有一个带有5个标签的UITabBarController。我希望能够在Tab栏上方的所有选项卡上显示ViewController。目前我遇到的问题是,当我以模态方式呈现ViewController时,它是不可见的。每当我在tableView中选择一行时,我都会调用此函数:

调用showPlayerView的tableView定义如下:

class SearchResultsTableView: UIView, UITableViewDataSource, UITableViewDelegate

searchResultsTableView是另一个类中定义的视图:

TestViewController: UIViewController, UserSearchDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate, UINavigationControllerDelegate

这是实际功能:

func showPlayerView() {
    let playerView = PlayerView()
    playerView.modalPresentationStyle = .overCurrentContext
    CustomTabBarController.sharedInstance?.present(playerView, animated: true, completion: {

    })
}

我设置了CustomTabBarController sharedInstance,如下所示:

static var sharedInstance : CustomTabBarController?

viewDidLoad()里面我有这个:

CustomTabBarController.sharedInstance = self

为什么我看不到我的模态ViewController,如何让它在所有屏幕上显示?

1 个答案:

答案 0 :(得分:0)

func showPlayerView() {
    let playerView = PlayerView()
    playerView.modalPresentationStyle = .overCurrentContext
    CustomTabBarController.sharedInstance?.tabBarController?.tabBar.hidden = true  // This will hide tab bar of your UITabbarViewController.
    CustomTabBarController.sharedInstance?.present(playerView, animated: true, completion: {

    })
}

// Make it visible in ViewWillApear method by below line

CustomTabBarController.sharedInstance?.tabBarController?.tabBar.hidden = false