使用cococaPods导入第三方MMDrawerController 库
项目中创建Podfile文件中
pod 'MMDrawerController','~>0.5.7'
终端中输入
pod install 下载类库
OC中导过后可以直接使用,但是swift中由于类库是OC代码不能直接使用。
需要如下几步解决:
1.创建新的.h文件,
2.删除全部的内容,然后添加 #import "MMDrawerController.h"
3.点击target->Build Settings->在搜索框中输入bridg->找到Objective-C Bridging Header 中添加.h文件的路径
在AppDelegate中:
var drawerController:MMDrawerController!
然后就封装一个方法:
func createDrawerController(){
//设置视图
let LVC = LeftViewController()
let CenterVC = MyTabBarViewController()
let CenterNC = UINavigationController.init(rootViewController: CenterVC)
drawerController = MMDrawerController(centerViewController: CenterNC,leftDrawerViewController: LVC)
drawerController.maximumLeftDrawerWidth = UIScreen.mainScreen().bounds.width * 0.7
//添加手势
drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureMode.All
drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.All
//设置动画,这里是设置打开侧栏透明度从0到1
drawerController.setDrawerVisualStateBlock { (drawerController, drawerSide, percentVisible) in
var sideDrawerViewController:UIViewController?
if(drawerSide == MMDrawerSide.Left){
sideDrawerViewController = drawerController.leftDrawerViewController
}
sideDrawerViewController?.view.alpha = percentVisible
}
self.window?.rootViewController = drawerController
window?.makeKeyAndVisible()
}
在
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {}中调用上面封装的方法,侧滑抽屉效果即可实现(⊙o⊙)哦!