ios - Xcode Swift 3d 快捷方式触摸导航栏不显示

标签 ios swift uinavigationbar shortcut 3dtouch

所以我刚刚在我的应用程序中添加了 3d 快捷方式。现在他们打开了正确的 ViewController 但我无法浏览应用程序的其余部分。它似乎将 ViewController 作为 modal 打开。如何让导航栏也显示出来?

这里的代码是AppDelegate.swift:

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

        if shortcutItem.type == "Micheal-Smith.Pathfinder-Society.charLog"
        {
            let sb = UIStoryboard(name: "Main", bundle: nil)
            let charLog = sb.instantiateViewController(withIdentifier: "CharacterLog") as! CharactersTableViewController
            let root = UIApplication.shared.keyWindow?.rootViewController

            root?.present(charLog, animated: false, completion: { 
                completionHandler(true)
            })
        }
        else if shortcutItem.type == "Micheal-Smith.Pathfinder-Society.gmTools"
        {
            let sb = UIStoryboard(name: "Main", bundle: nil)
            let charLog = sb.instantiateViewController(withIdentifier: "gmTools") as! UITabBarController
            let root = UIApplication.shared.keyWindow?.rootViewController

            root?.present(charLog, animated: false, completion: {
                completionHandler(true)
            })
        }
    }

最佳答案

处理 VC 显示的另一种方法是将 VC 嵌入导航 Controller 中。然后,您将为 NavigationController 提供一个 Storyboard ID。然后你会把它呈现在屏幕上。这是一个例子:

let sb = UIStoryboard(name: "Main", bundle: nil)
        let charLog = sb.instantiateViewController(withIdentifier: "CharacterLog") as! UINavigationController 
        let root = UIApplication.shared.keyWindow?.rootViewController
root.present(charLog, animated: false, completion: { 
            completionHandler(true)
        })

“CharacterLog”将被设置为 NavigationController StoryBoard ID 而不是 ViewController,如下面的链接所示。

https://www.screencast.com/t/mcG5v5gvz

我也会将其发布在答案中,但这是我为您制作的 Github 教程的链接。

https://github.com/karpisdiem/3D-Quick-Qctions-Swift

关于ios - Xcode Swift 3d 快捷方式触摸导航栏不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41979032/

相关文章:

ios - 如何根据NSDate计算年龄

ios - 如何在 UIlabel 中将上标 % 字符显示为字符串?

ios - 钥匙串(keychain)返回零

ios - 在 iOS Swift 中更改导航栏项目的 alpha 值

iphone - Modal UIViewController 总是在 iPad 上全屏显示。为什么?

android - 你如何管理你的 Assets ?

ios - 自动布局 View 层次结构

swift - 为什么不在 Swift 中使用基于结构的单例

ios - 我能以某种方式使 UINavigationBar 在 iOS 7 和 iOS 8 中看起来像 iOS 6 UINavigationBar

iOS 7,使用默认的 interactivePopGestureRecognizer 快速向后滑动时损坏 UINavigationBar