DualSlideMenu 1.7.3

DualSlideMenu 1.7.3

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2016 年 5 月
SPM支持 SPM

Vincent Le 维护。



  • 作者:
  • Vincent Le

DualSlideMenu

左右滑动菜单以保持主视图整洁

目录

为什么使用这个

  • 通过为您的应用程序添加更多空间,整理主视图
  • 添加简单的动画以提高用户体验
  • 有大量关于方法和函数的文档,以提高可用性
  • 易于自定义
  • 您的应用程序可以看起来像 Slack、Facebook 以及许多 Google 的应用程序

演示

Video Walkthrough

教程

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install。然后,运行示例项目并检查例子。

要求

安装

创建一个主视图控制器,它可以被认为是应用程序的首页,然后创建另外两个视图控制器作为左侧和右侧菜单,并在 AppDelegate 中为这三个视图控制器添加标识符。

identifier

在你的 AppDelegate 文件中添加 pod 到文件中。
  import DualSlideMenu
然后,使用上面提供的标识符初始化,并将三个视图控制器添加到容器类中
  var window: UIWindow?
  var storyboard: UIStoryboard?


  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    window = UIWindow(frame: UIScreen.mainScreen().bounds)
      storyboard = UIStoryboard(name: "Main", bundle: nil)


      let leftView = storyboard?.instantiateViewControllerWithIdentifier("LeftMenuController")
      let rightView = storyboard?.instantiateViewControllerWithIdentifier("RightMenuController")
      let mainView = storyboard?.instantiateViewControllerWithIdentifier("MainController")

      let controller = DualSlideMenuViewController(mainViewController: mainView!, leftMenuViewController: leftView!, rightMenuViewController: rightView!)
      window!.rootViewController = controller
      window!.makeKeyAndVisible()
      return true
  }
如果只想为菜单使用特定的侧面,请使用以下方法进行初始化
let leftView = storyboard?.instantiateViewControllerWithIdentifier("LeftMenuController")
let mainView = storyboard?.instantiateViewControllerWithIdentifier("MainController")

let controller = DualSlideMenuViewController(mainViewController: mainView!, leftMenuViewController: leftView!)
可以通过在AppDelegate的didFinishLaunchWithOptions方法内部添加以下代码来更改侧边菜单的显示宽度。左右两侧边菜单都必须添加偏移量
controller.leftSideOffset = 200
controller.rightSideOffset = 200
//200 represents the width of the main view when the side menu is present
如果你决定添加打开菜单的其他操作(如汉堡按钮),则只需调用DualSlideMenuViewController的toggle方法,并传入主视图应移动的方向参数。我知道这可能不太直观,但请将此参数视为不是侧视图出现的位置,而是主视图移动的方向
controller.toggle('right')
//This will open the left side view and move the main view to the RIGHT (KEYWORD)
无动画切换视图
controller.toMain() // main view appears without animation
controller.toLeft() // left view appears without animation
controller.toRight() // right view appears without animation
另一方面,如果你希望使用实际动画切换到主视图
controller.collapseAll()
如果你希望向侧边菜单添加滑动手势,现在你可以这样做
controller.addSwipeGestureInSide(rightView!, direction: .Right)
controller.addSwipeGestureInSide(leftView!, direction: .Left)

代理方法

func onSwipe() {
  // Called when the user has swiped from any view
}

func didChangeView() {
  // Called when asynchronous animation has completed
}

完整API

[返回顶部]

  // Initializers
  public convenience init(mainViewController: UIViewController, leftMenuViewController: UIViewController)
  public convenience init (mainViewController: UIViewController, rightMenuViewController: UIViewController)
  public convenience init(mainViewController: UIViewController, leftMenuViewController: UIViewController, rightMenuViewController: UIViewController) 

  /**
    Add swipe gestures in side view
    Useful when side view takes up the whole screen so the only way to navigate to home is with this swipe gesture

    - parameter viewController: the view controller that a recognizer will be added to
    - parameter direction:      the direction of type UISwipeGestureRecognizierDirection
   */
  public func addSwipeGestureInSide(viewController: UIViewController, direction: UISwipeGestureRecognizerDirection)

  /**
    Main toggle function that controls navigation of side menu

    - parameter swipeDirection: the direction of the swipe
    ex. "left" or "right" where swiping from left to right is a "right" swipe
   */
  public func toggle(swipeDirection: String)

  /**
    This is an escape method that will animate to the main view no matter what view the app is currently in

    This method will not animate the transition, so the main view will appear in view instantly
    Up to developers to decide which to use for their use case
   */
  public func toMain()

  /**
    Similar to toMain, except instantly animates to left menu
   */
  public func toLeft()

  /**
    Similar to toMain, except instantly animates to right menu
   */
  public func toRight() 

  /**
    Will move to main view from either left or right menu.
    Pretty straight forward, this is a cleaner implementation of toMain and does include animations
    Up to developers to decide to fit their use case
   */
  public func collapseAll() 

新滑动手势识别器概述

[返回顶部]
Video Walkthrough

贡献

[返回顶部] 我很高兴接受任何开放贡献。请克隆此项目,进行修改并提交拉取请求。

作者

[返回顶部]

Vincent Le, [email protected]

授权协议

[返回顶部]

DualSlideMenu遵循MIT许可协议。更多信息请参阅LICENSE文件。