LNSideMenu
[](https://travis-ci.org/Luan Nguyen/LNSideMenu)
这个基本与 GitHub 上许多用于 iOS 的类似,但除了必须的功能之外,它还提供了一些有趣的功能,专注于效果和动画,如滚动效果、菜单项出现的淡入动画等。让我们一起探索并享受它吧。
快速入门
1. 按顺序创建一个从 LNSideMenuNavigationController 继承的 UINavigationController 子类
2. 基于源视图初始化菜单视图
func initialSideMenu(_ position: Position) {
sideMenu = LNSideMenu(sourceView: view, menuPosition: position, items: items!)
sideMenu?.menuViewController?.menuBgColor = UIColor.black.withAlphaComponent(0.85)
sideMenu?.delegate = self
// Bring navigationBar to front if needed
view.bringSubview(toFront: navigationBar)
}
3. 实现委托方法:didSelectItemAtIndex,...
4. 要更改内容视图控制器:从您的 UINavigationController 子类中获取目的地并将它设置为内容视图控制器。
func didSelectItemAtIndex(index: Int) {
// TODO: Get your destViewController here
self.setContentViewController(destViewController)
}
5. 切换菜单
self.sideMenuManager?.toggleSideMenuView()
6. 通过以下代码添加这些代码以实现使导航栏透明
self.navigationBarTranslucentStyle()
sideMenuManager?.sideMenuController()?.sideMenu?.isNavbarHiddenOrTransparent = true
7. 查看 示例
获取全面的视图。
自己的菜单
在NavigationController子类中初始化侧边菜单如下:库目前提供4种可调整大小类型,尤其是完整、一半、三分之二和自定义(CGFloat)。
func initialCustomMenu(pos position: Position) {
let menu = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LeftMenuTableViewController") as! LeftMenuTableViewController
menu.delegate = self
sideMenu = LNSideMenu(sourceView: view, menuPosition: position, customSideMenu: menu)
sideMenu?.delegate = self
// Enable dynamic animator
sideMenu?.enableDynamic = true
// Moving down the menu view under navigation bar
sideMenu?.underNavigationBar = true
}
可配置属性
. disabled: default is false, disabled/enabled sidemenu
. enableDynamic: default is true, disabled/enabled dynamic animator
. enableAnimation: default is true, showing side menu with fade animation
. Gesture recognizers: allowLeftSwipe, allowRightSwipe, allowPanGesture: default is true
. animationDuration: default is 0.5, show/hide sidemenu animation duration
. hideWhenDidSelectOnCell: default is true, the sidemenu is hidden when selecting an item on menu
. SideMenu custom colors:
- menuBgColor: default is purpleColor
- itemBgColor: default is whiteColor
- highlightColor: default is redColor
- titleColor: item title color, default is blackColor
需求
. Xcode 8
. iOS 8 或更新
. Swift 3/4
安装
Cocoapods
LNSideMenu可以通过Cocoapods获取。要安装它,只需将以下行添加到您的Podfile中。
Swift 3
pod 'LNSideMenu', '~> 2.3'
Swift 4
pod 'LNSideMenu', '~> 3.0'
手册
将LNSideMenu文件夹中的所有文件添加到您的项目文件夹中
TODO
更改内容视图控制器动画
贡献
如果您有兴趣并且愿意投入时间进行贡献,我将非常感激。
作者
Luan Nguyen
许可协议
LNSideMenu 项目采用了 MIT 许可协议。更多信息请查阅 LICENSE 文件。