Ios 如何从选项卡栏项显示popover?

Ios 如何从选项卡栏项显示popover?,ios,swift,uitabbarcontroller,swift4,uitabbar,Ios,Swift,Uitabbarcontroller,Swift4,Uitabbar,我想在Swift 4中将ViewController显示为popover,但它通常显示ViewController,以下是代码: class CustomTabBarController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() let favViewController = TrialViewController() let exhi

我想在Swift 4中将
ViewController
显示为popover,但它通常显示
ViewController
,以下是代码:

class CustomTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let favViewController = TrialViewController()
        let exhibtionViewController = TrialViewController()
        let menuViewController = ttttViewController()
        let notificationViewController = TrialViewController()
        let profileViewController = ttttViewController()

        favViewController.tabBarItem.title = "first"
        exhibtionViewController.tabBarItem.title = "second"
        menuViewController.tabBarItem.title = "third"
        notificationViewController.tabBarItem.title = "forth"
        profileViewController.tabBarItem.title = "fifth"

        favViewController.tabBarItem.image = UIImage(named:"home25")
        exhibtionViewController.tabBarItem.image = UIImage(named: "bag25")
        menuViewController.tabBarItem.image = UIImage(named: "main_add_25")
        notificationViewController.tabBarItem.image = UIImage(named: "notification25")
        profileViewController.tabBarItem.image = UIImage(named: "man_man25")


        let tabBarItemWidth = Int(self.tabBar.frame.size.width) / (self.tabBar.items?.count)!
        let x = tabBarItemWidth * 3;
        let newRect = CGRect(x: x, y: 0, width: tabBarItemWidth, height: Int(self.tabBar.frame.size.height))
        print(newRect)

        menuViewController.modalPresentationStyle = .popover
        menuViewController.view.frame = newRect
        menuViewController.preferredContentSize = CGSize(width: 150,height: 150)

        if let popoverMenuViewController = menuViewController.popoverPresentationController {
            popoverMenuViewController.permittedArrowDirections = .down
            popoverMenuViewController.delegate = menuViewController as? UIPopoverPresentationControllerDelegate
            popoverMenuViewController.sourceRect = newRect
            popoverMenuViewController.sourceView = self.tabBar

            present(menuViewController, animated: true, completion: nil)

        }

        viewControllers = [favViewController, exhibtionViewController, menuViewController, notificationViewController, profileViewController]
    }

}
我的代码有什么问题

override func viewDidAppear(_ animated: Bool) {

    let vc = self.storyboard?.instantiateViewController(withIdentifier: "bbb") as! ttttViewController
    vc.modalPresentationStyle = .popover //presentation style

    vc.preferredContentSize = CGSize(width: 150,height: 150)
    vc.popoverPresentationController?.delegate = self as! UIPopoverPresentationControllerDelegate
    vc.popoverPresentationController?.sourceView = view
    vc.popoverPresentationController?.sourceRect = self.tabBar.frame
    self.present(vc, animated: true, completion: nil)


}


func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return  .none
}
演示在这里


任何选项卡都不显示相同的结果不是这样,而是应该从menuViewController选项卡显示相同的结果