Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用UITabBar使3D触控快速动作生效?_Ios_Swift_Uitabbarcontroller_3dtouch - Fatal编程技术网

Ios 如何使用UITabBar使3D触控快速动作生效?

Ios 如何使用UITabBar使3D触控快速动作生效?,ios,swift,uitabbarcontroller,3dtouch,Ios,Swift,Uitabbarcontroller,3dtouch,我已经为此挣扎了几个小时 我有一个UITabBarController,里面有一个UINavigationController,里面有一个带有tableview的ViewController 所有教程都以NavigationController为父级,所有内容都在其中 下面是我的Main.storyboard的外观(我正在尝试使快捷方式转到最上面一行的第三个ViewController,或第二行的第二个ViewController): 这是我的info.plist文件的一部分: &l

我已经为此挣扎了几个小时

我有一个UITabBarController,里面有一个UINavigationController,里面有一个带有tableview的ViewController

所有教程都以NavigationController为父级,所有内容都在其中

下面是我的
Main.storyboard
的外观(我正在尝试使快捷方式转到最上面一行的第三个ViewController,或第二行的第二个ViewController):


这是我的
info.plist
文件的一部分:

    <key>UIApplicationShortcutItems</key>
    <array>
        <dict>
            <key>UIApplicationShortcutItemIconType</key>
            <string>UIApplicationShortcutIconTypeHome</string>
            <key>UIApplicationShortcutItemTitle</key>
            <string>Home</string>
            <key>UIApplicationShortcutItemType</key>
            <string>com.emmetarries.Tabbed-Test.home</string>
        </dict>
        <dict>
            <key>UIApplicationShortcutItemIconType</key>
            <string>UIApplicationShortcutIconTypeLatest</string>
            <key>UIApplicationShortcutItemTitle</key>
            <string>Latest Photo</string>
            <key>UIApplicationShortcutItemType</key>
            <string>com.emmetarries.Tabbed-Test.latestPhoto</string>
        </dict>
    </array>
UIApplicationShortcutItems
:目标-C

:目标-C

我已经尝试了在Stack Overflow和Youtube上找到的所有教程



有人知道这是怎么做到的吗?或者你有没有在Swift 3中找到的教程来解释这一点?我可以重新排序/排列我的视图,但我还没有找到一个好方法。

试试这个:

在AppDelegate.swift中:

enum QuickAction: String {
case Home = "home"
case LatestPhoto = "latestPhoto"

init?(fullIdentifier: String) {
    guard let shortcutIdentifier = fullIdentifier.components(separatedBy: ".").last else {
        return nil
    }

    self.init(rawValue: shortcutIdentifier)
 }
}
我们将使用它来确定您选择的操作。然后我们需要实现函数来处理操作:

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    completionHandler(handleQuickAction(shortcutItem: shortcutItem))
}

private func handleQuickAction(shortcutItem: UIApplicationShortcutItem) -> Bool {
    let shortcutType = shortcutItem.type
    guard let shortcutIdentifier = QuickAction(fullIdentifier: shortcutType)
        else {
            return false
    }

    guard let tabBarController = window?.rootViewController as? UITabBarController else {
      return false
    }

    switch shortcutIdentifier {
    case .Home:
        tabBarController.selectedIndex = 0
    case .LatestPhoto:
        tabBarController.selectedIndex = 1
    }
    return true
}

就这样

试试这个:

在AppDelegate.swift中:

enum QuickAction: String {
case Home = "home"
case LatestPhoto = "latestPhoto"

init?(fullIdentifier: String) {
    guard let shortcutIdentifier = fullIdentifier.components(separatedBy: ".").last else {
        return nil
    }

    self.init(rawValue: shortcutIdentifier)
 }
}
我们将使用它来确定您选择的操作。然后我们需要实现函数来处理操作:

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    completionHandler(handleQuickAction(shortcutItem: shortcutItem))
}

private func handleQuickAction(shortcutItem: UIApplicationShortcutItem) -> Bool {
    let shortcutType = shortcutItem.type
    guard let shortcutIdentifier = QuickAction(fullIdentifier: shortcutType)
        else {
            return false
    }

    guard let tabBarController = window?.rootViewController as? UITabBarController else {
      return false
    }

    switch shortcutIdentifier {
    case .Home:
        tabBarController.selectedIndex = 0
    case .LatestPhoto:
        tabBarController.selectedIndex = 1
    }
    return true
}

就这样

嘿,你试过更改选项卡栏了吗?selectedIndex?@antoinebelldev是的,我想我已经弄明白了,但是现在已经很晚了,我要睡觉了,所以我明天会发布我的发现!好的,太好了,如果有机会的话,我会在下面发布我的答案。嘿,你试过更改选项卡栏了吗?selectedIndex?@antoinebelldev是的,我想我已经弄明白了,但是时间太晚了,我要睡觉了,所以我明天会发布我的发现!好的,太好了,如果有机会,我会把我的答案贴在下面。谢谢!我明天早上再看!我基本上有你放在那里的东西。我真的需要
latesthoto
快捷方式才能转到最上面一行的第三个(最右)VC。我发现了一些可以做到这一点的东西,但在退出应用程序后启动应用程序时,它就不起作用了。只有当应用程序已经在后台时,它才起作用。要看到这一点,请下载项目:,你知道为什么吗??非常感谢。谢谢我明天早上再看!我基本上有你放在那里的东西。我真的需要
latesthoto
快捷方式才能转到最上面一行的第三个(最右)VC。我发现了一些可以做到这一点的东西,但在退出应用程序后启动应用程序时,它就不起作用了。只有当应用程序已经在后台时,它才起作用。要看到这一点,请下载项目:,你知道为什么吗??非常感谢。