我已经为此苦苦挣扎了几个小时。
我有一个 UITabBarController,里面有 UINavigationController,里面有一个 ViewController,里面有一个 tableview。
所有教程都以 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>
我已经研究过这些:
DuckDuckGoed:“使用 UITabBarController 进行 3D 快速操作”,除以下内容外没有结果。
Handle 3D Touch quick actions with UITabBarController and UINavigationController : objective-C
iOS 9 selecting tabbar index with quick actions, performActionForShortcutItem : objective-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)
}
}
我们将使用它来确定您选择的操作。然后我们需要实现处理 Action 的函数:
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
}
完成了!
关于ios - 如何使 3D Touch Quick Action 与 UITabBar 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43303642/