0

当我在主屏幕上按下 3D Touch 时工作正常,但不显示导航和标签栏,如何使用 3D Touch 呈现导航和标签栏?不知道如何在应用程序启动后覆盖自定义点。感恩米勒

class AppDelegate: UIResponder, UIApplicationDelegate {    
enum ShortcutIdentifier: String {
    case First
    case Second
    case Third
    case Fourth
    //Initializers
    init?(fullType: String) {
        guard let last = fullType.components(separatedBy: ".").last else { return nil }
        self.init(rawValue: last)
    }
    //Properties
    var type: String {
        return Bundle.main.bundleIdentifier! + ".\(self.rawValue)"
    }
}
var window: UIWindow?

/// Saved shortcut item used as a result of an app launch, used later when app is activated.
var launchedShortcutItem: UIApplicationShortcutItem?

func handleShortCutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
    var handled = false

    // Verify that the provided shortcutItem type is one handled by the application.
    guard ShortcutIdentifier(fullType: shortcutItem.type) != nil else { return false }

    guard let shortCutType = shortcutItem.type as String? else { return false }

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    var vcc = UIViewController()

    switch (shortCutType) {
    case ShortcutIdentifier.First.type:
        vcc = storyboard.instantiateViewController(withIdentifier: "VC1")
        handled = true
        break
    case ShortcutIdentifier.Second.type:
        vcc = storyboard.instantiateViewController(withIdentifier: "VC2")
        handled = true
        break
    case ShortcutIdentifier.Third.type:
        vcc = storyboard.instantiateViewController(withIdentifier: "VC3")
        handled = true
        break
    case ShortcutIdentifier.Fourth.type:
        vcc = storyboard.instantiateViewController(withIdentifier: "VC4")
        handled = true
        break
    default:
        break
    }
    // Display the selected view controller
    self.window?.rootViewController?.present(vcc, animated: true, completion: nil)

    return handled
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    let handledShortCutItem = handleShortCutItem(shortcutItem)

    completionHandler(handledShortCutItem)
}
func applicationDidBecomeActive(_ application: UIApplication) {
    guard launchedShortcutItem != nil else { return }

    //handleShortCutItem(shortcut)
    launchedShortcutItem = nil
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    // If a shortcut was launched, display its information and take the appropriate action
    if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {

        launchedShortcutItem = shortcutItem
    }
    return true
}

在此处输入图像描述

4

1 回答 1

0

如何使用 3D Touch 呈现导航和标签栏

与您在应用程序正常运行期间执行此操作的方式相同。你不应该做一些特殊的事情来响应用户按下快捷方式项(即你的self.window?.rootViewController?.present,它实际上只是建立了一个临时的外观);您应该导航到快捷项对应的实际应用程序的实际区域。

于 2016-12-04T16:40:12.273 回答