如何通过 3D Touch 快速项目转到特定的标签栏视图

How to go to specific tab bar view via 3D Touch quick items

我正在尝试转到故事板中的 3 个选项卡栏元素中的任何一个,具体取决于我 select 在应用程序图标上进行 3D 触摸时的快速操作。我希望仍然能够看到选项卡栏控制器,这是我最近一直在努力的地方。 任何帮助将不胜感激。

编辑:我已经得到它去每个单独的标签栏项目。

我现在需要在每个视图中激活 segue,这是我正在使用的代码:

    func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    let myTabBar = self.window?.rootViewController as? UITabBarController
    let NavigationController = UINavigationController.self
    if shortcutItem.type == "com.LukeB.Quick-Actions-Test.Three" {
        myTabBar?.selectedIndex = 2
        //Need to go to the segue with identifier SegueThree
    }
    if shortcutItem.type == "com.LukeB.Quick-Actions-Test.Two" {
        myTabBar?.selectedIndex = 1
        //Need to go to the segue with identifier SegueThree

    }
    if shortcutItem.type == "com.LukeB.Quick-Actions-Test.One" {
        myTabBar?.selectedIndex = 0
        //Need to go to the segue with identifier SegueOne


    }
}

UIApplicationDelegate 的快速操作处理程序 here 的文档中解释了您正在寻找的行为。总而言之,您需要检查 willFinishLaunchingdidFinishLaunching 中的启动选项,然后根据您看到的内容决定要做什么。

您遇到的问题可能是由您如何设置应用中首次显示的视图引起的。您可能将 ViewController 设置为嵌套在选项卡视图控制器中的那个,而不是将其设置为选项卡控制器,然后告诉选项卡控制器要显示其哪个视图。

这只是猜测,您需要分享更多代码才能获得更具体的答案。

更新: 既然您已经解决了显示正确选项卡的问题,您希望该视图在其之上继续显示另一个视图。

UITabBarControllerdocumentation 在名为 "The Views of a Tab Bar Controller" 的部分中给出了一些有关如何执行此操作的提示。做你想做的事情的一种方法是设置你的 UIViewControllers 以便每个选项卡都有一个导航控制器作为根。这样,您就可以以用户可以识别的方式将您想要的任何控制器推送到视图上。


     UINavigationController - Controller 1 -> push new controller
    /
TBC - UINavigationController - Controller 2 -> push new controller
    \
     UINavigationController - Controller 3 -> push new controller

或者,如果您有想要使用的自定义转场,您可以继续使用 myTabBar?.selectedViewController.performSegue(withIdentifier:sender:)

进行的操作