Swift SideMenu显示视图控制器

时间:2017-01-23 10:41:08

标签: ios swift menu

所以我有一个表格视图控制器并使用https://github.com/jonkykong/SideMenu我试图显示一个“滑入”侧边栏,但它没有显示我在侧边栏中想要的视图是黑

enter image description here

// Define the menus
let menuLeftNavigationController = UISideMenuNavigationController()
menuLeftNavigationController.leftSide = true
// UISideMenuNavigationController is a subclass of UINavigationController, so do any additional configuration of it here like setting its viewControllers.
SideMenuManager.menuLeftNavigationController = menuLeftNavigationController

// Enable gestures. The left and/or right menus must be set up above for these to work.
// Note that these continue to work on the Navigation Controller independent of the View Controller it displays!
SideMenuManager.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)
SideMenuManager.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)

当它点击侧边栏按钮时,我有这个,它会创建动画,但不会显示视图控制器

func someAction(){
    present(SideMenuManager.menuLeftNavigationController!, animated: true, completion: nil)
    debugPrint("clicked")
}

enter image description here

6 个答案:

答案 0 :(得分:2)

答案在您发布的代码段的评论中:

// UISideMenuNavigationController is a subclass of UINavigationController, 
// so do any additional configuration of it here like setting its viewControllers.

答案 1 :(得分:1)

您可以使用InteractiveSideMenu库来实施幻灯片菜单。它是一个非常新的,支持良好的库,易于实现。许多自定义选项让您可以比通常的侧边栏做更多的事情。

image

答案 2 :(得分:1)

在回购自述文件中,您将找到答案,查看自定义  第https://github.com/jonkykong/SideMenu#sidemenumanager节。

只需设置menuFadeStatusbar = false

即可
SideMenuManager.default.menuFadeStatusBar = false

在上一个链接中,您将找到以下信息:"在状态栏后面绘制menuAnimationBackgroundColor。默认为true。 如果menuFadeStatusBar为真,则使用此颜色淡化它。默认为黑色。"

答案 3 :(得分:0)

我可以推荐使用JASidePanels

这很简单,只是有效。您正在创建一个 JASidePanelController ,将此类设置为在Storyboard中清空viewcontroller并使该控制器初始化。 (不要忘记在班级顶部import JASidePanels

然后,在本课程中,您将实现awakeFromNib()这样的方法:

leftPanel = ..//instantiating menu controller
let centerController = ...//instantiating center controller
centerPanel = UINavigationController(rootViewController: centerController)

就是这样。 您可以通过ID进行实例化控制,ID可以在Identity Inspector中设置

let stb = UIStoryboard(name: "Main", bundle: nil) //instantiating a storyboard we will use for instantiating controllers
let someController = stb.instantiateViewController(withIdentifier: "here_your_identifier_goes") as! YourControllerClass

答案 4 :(得分:0)

      let btnMenu:UIButton = UIButton()
    btnMenu.frame = CGRect(x: 20*valuePro, y: 20*valuePro, width: 40*valuePro, height: 40*valuePro)
    btnMenu.backgroundColor = .red
    btnMenu.addTarget(self, action: #selector(self.displayMenu), for: .touchUpInside)
    self.view.addSubview(btnMenu)
@objc func displayMenu(sender: UIButton!) {
    print("Button Clicked")
    present(SideMenuManager.default.menuLeftNavigationController!, animated: true, completion: nil)
}

答案 5 :(得分:0)

https://github.com/jonkykong/SideMenu

SideMenu自述文件

代码实现

第一:

import SideMenu

通过按钮执行以下操作:

// Define the menu
let menu = UISideMenuNavigationController(rootViewController: YourViewController)
// UISideMenuNavigationController is a subclass of UINavigationController, so do any additional configuration 
// of it here like setting its viewControllers. If you're using storyboards, you'll want to do something like:
// let menu = storyboard!.instantiateViewController(withIdentifier: "RightMenu") as! UISideMenuNavigationController
present(menu, animated: true, completion: nil)

答案

您需要使用UISideMenuNavigationController(rootViewController:),而不是UISideMenuNavigationController()

如果您从左侧打开侧面菜单,请将leftSide设置为true

let menu = UISideMenuNavigationController(rootViewController: YourViewController)
menu.leftSide = true
present(menu, animated: true, completion: nil)

当然,您应该将实例变量赋予UISideMenuNavigationController(rootViewController:)