3D Touch 操作不起作用(swift 3)

克里斯·博诺

所以,我已经设法让一切都正确连接起来。当按下快捷操作时,我会在控制台中得到正确的打印输出。我从这里去哪里?我想不通...

这是我在 App Delegate 中的代码

    var quicklaunch: Bool!
    var viewName: String?

   func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
    viewName = shortcutItem.type
    quicklaunch = true
    completionHandler(quicklaunch)
}

func applicationDidBecomeActive(application: UIApplication) {
    if quicklaunch == true {
        quicklaunch = false
        if viewName == "Messages" {
            let rootViewController = self.window?.rootViewController
            let popUpController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FriendsVC")
            rootViewController?.present(popUpController, animated: true, completion: nil)
            print("Worked")
        }
    }  
}

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    if quicklaunch == false {
        quicklaunch = true
        if viewName == "Messages" {
            let rootViewController = self.window?.rootViewController
            let popUpController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FriendsVC")
            rootViewController?.present(popUpController, animated: true, completion: nil)
            print("Worked")
        }
    }

}

如何让它弹出到正确的视图控制器?

马利克

您可以获得rootViewController,然后以viewController模态方式呈现所需的内容(如果您rootViewController是 ,则将其推送到导航堆栈上UINavigationController)。类似的东西

let rootViewController = self.window?.rootViewController
let popUpController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "???") as! ???
rootViewController.present(popUpController, animated: true, completion: nil)

替换???为相应的值

编辑

在您的 AppDelegate 中创建一个布尔变量并调用quickLaunch一个字符串变量viewName然后更新下面两个方法

func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
    viewName = shortcutItem.type
    quickLaunch = true
    completionHandler(quickLaunch)
}

func applicationDidBecomeActive(application: UIApplication) {
    if quickLaunch == true {
        quickLaunch = false
        //PRESENT YOUR VIEW MODALLY HERE
    }  
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章