- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个使用 SwRevealViewController 的侧面菜单。我已经使用界面生成器进行了设置,并且正在按照所需的方式工作。这是storyBoard的设计
按照应用程序流程,它总是需要经过处理菜单的红色导航 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/
我几乎已经构建了一个应用程序,但我想在显示 View 或侧 View 的标签中显示当前用户的电子邮件地址。显示 View 是一个 TableView Controller ,登录 View 是一个简单
我有一个使用 SwRevealViewController 的侧面菜单。我已经使用界面生成器进行了设置,并且正在按照所需的方式工作。这是storyBoard的设计 按照应用程序流程,它总是需要经过处理
我是一名优秀的程序员,十分优秀!