选择 tabBar 项时如何以模态方式呈现 viewController [英] How to present a viewController modally when it's tabBar item is selected
问题描述
我有一个带有 UITabBarController
和 5 个 UITabBarItem
的应用程序.我想以模态方式为第三个标签栏项目(相机控制器)启动一个视图控制器.
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).
我试过这个代码:
override func viewDidLoad() {
super.viewDidLoad()
self.presentViewController(self, animated: true, completion: nil)
}
但是我的应用程序崩溃了.我该怎么办?
But my app crashed. What should I do?
推荐答案
如果你想要一个浮动的中心按钮(或类似的东西),你基本上需要一个空的标签,用作你在特定位置添加的自定义按钮的占位符坐标.
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.
您将这个新按钮添加为选项卡栏的子视图,只需从用户按下它即可打开您的模态对话框.它在标签栏上所需的空间由其下方的空白和禁用项目提供.除了提供父视图之外,tabbarcontroller 与它无关.如果您将标签图像设置为 nil,将标题设置为空并禁用它,那么它就是您可以放置自己的按钮的空白空间.
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.
这篇关于选择 tabBar 项时如何以模态方式呈现 viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!