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

问题描述 投票:-1回答:1

我试图在我的故事板中找到3个标签栏元素中的任何一个,具体取决于我在应用程序图标上触摸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


    }
}
ios swift ios12 3dtouch
1个回答
2
投票

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

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

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

更新:现在您已经解决了正确的选项卡显示的问题,您希望该视图在其上方隔离另一个视图。

documentationUITabBarController在“标签栏控制器的视图”一节中给出了一些如何做到这一点的提示。执行您尝试执行的操作的一种方法是设置UIViewControllers,以便每个选项卡都有一个导航控制器作为根。这样,您可以以用户将识别的方式将您想要的任何控制器推送到视图上。


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

或者,如果你想要使用自定义segue,你可以继续使用myTabBar?.selectedViewController.performSegue(withIdentifier:sender:)做的事情。

© www.soinside.com 2019 - 2024. All rights reserved.