左右滑动菜单以保持主视图整洁
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
。然后,运行示例项目并检查例子。
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!)
controller.leftSideOffset = 200
controller.rightSideOffset = 200
//200 represents the width of the main view when the side menu is present
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
}
[返回顶部]
// 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()
[返回顶部]
[返回顶部] 我很高兴接受任何开放贡献。请克隆此项目,进行修改并提交拉取请求。
[返回顶部]
Vincent Le, [email protected]
[返回顶部]
DualSlideMenu遵循MIT许可协议。更多信息请参阅LICENSE文件。