问题
I have an app with a UITabBarController
and 5 UITabBarItem
s. I would like to launch modally a View Controller for the third tab-bar item (camera controller).
I tried this code:
override func viewDidLoad() {
super.viewDidLoad()
self.presentViewController(self, animated: true, completion: nil)
}
But my app crashed. What should I do?
回答1:
If you want a floating center button (or something similar) you basically need an empty tab that is used as a placeholder for a custom button that you add at specific coordinates.
This new button you add as a subview of the tabbar and simply open your modal dialog from the user pressing it. The space it requires on the tabbar is provided by the empty and disabled item below it. Other than providing the parent view the tabbarcontroller has nothing to do with it. If you set the tab image as nil, title as empty and disable it then it is just empty space where you can put your own button.
来源:https://stackoverflow.com/questions/28100050/how-to-present-a-viewcontroller-modally-when-its-tabbar-item-is-selected