gpt4 book ai didi

ios - 当 RevealView Controller 不存在时,如何使用 swrevealviewController 显示侧面菜单?

转载 作者:行者123 更新时间:2023-11-30 11:03:37 25 4
gpt4 key购买 nike

我有一个使用 SwRevealViewController 的侧面菜单。我已经使用界面生成器进行了设置,并且正在按照所需的方式工作。这是storyBoard的设计

Istoryboard

按照应用程序流程,它总是需要经过处理菜单的红色导航 View Controller ,黄色的是菜单 View ,绿色的是我在推送通知时需要呈现的一个 View Controller 已收到,无论应用程序状态如何。到目前为止,我可以做到这一点,使用以下代码转到绿色 View Controller 而不经过红色 View Controller :

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
print("did Recive remote")
if let messageID = userInfo["gcmMessageIDKey"] {
print("Message ID: \(messageID)")
}
print(userInfo)
completionHandler()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "porterDetail")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
}

该 View 之后不显示导航 Controller ,甚至无法使用此代码创建侧边菜单。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "SWRevealViewController") as! SWRevealViewController
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "ico_menu"), style: .plain, target: initialViewController, action: #selector(initialViewController.revealToggle(_:)))

但是菜单没有显示,也没有任何反应。知道如何在此 View 中显示菜单以允许用户出去,或者有什么其他方法可以查看并保持导航。

最佳答案

我终于解决了如何在收到推送通知时显示来自应用程序的侧边菜单。所以我们的想法是在 View Controller 呈现导航栏之前实例化一个导航 Controller 。

let menuVC = storyboard.instantiateViewController(withIdentifier: "menuVC")
let chatVC = storyboard.instantiateViewController(withIdentifier: "chatNC")
((chatVC as! UINavigationController).topViewController as! newChatViewController).id = id
let mainRWVC = storyboard.instantiateViewController(withIdentifier: "SWRevealViewController") as! SWRevealViewController
mainRWVC.setRear(menuVC, animated: true)
mainRWVC.setFront(chatVC, animated: true)
self.window?.rootViewController = mainRWVC
self.window?.makeKeyAndVisible()

然后在所呈现的导航的topViewcontroller中。检查 id 不为零,然后呈现下一个 View 。然后在呈现的 View 中。在加载此代码时显示侧边菜单。

 self.navigationItem.leftBarButtonItem = nil
let revealViewController = self.revealViewController()
revealViewController?.rearViewRevealWidth = ((UIScreen.main.bounds.width * 74.6875) / 100)
if revealViewController != nil{
let button1 = UIBarButtonItem(image: UIImage(named: "ico_menu"), style: .plain, target: self.revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:))) // action:#selector(Class.MethodName) for swift 3
self.navigationItem.leftBarButtonItem = button1
self.navigationItem.leftBarButtonItem?.tintColor = .white
}

瞧,侧面菜单出现并按预期工作。

关于ios - 当 RevealView Controller 不存在时,如何使用 swrevealviewController 显示侧面菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52997943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com