使用MMDrawerController以TabBarController為中心檢視實現抽屜效果
阿新 • • 發佈:2019-02-17
(1) MMDrawerController下載地址https://github.com/mutualmobile/MMDrawerController
(2)使用MMDrawerController以TabBarController為中心檢視,實現左檢視靜態cell可以push到對應介面。
(3)問題:遇到的問題是,當以左抽屜為根檢視push的時候,會出現不能滿屏,center檢視依然存在一部分,解決push滿屏的情況,就需要以center檢視為基礎進行push,但是center檢視主要是NavigationController如果以 UINavigationController * nav = (UINavigationController)self.mm_drawerController.centerViewController;這種方法去接收中心檢視的話,就會出現問題,因為此時的中心檢視TabBarController,用下面程式碼中的方法分部接受中心檢視,就可以實現MMDrawerController抽屜第三方庫可以基於TabBarController實現抽屜。QQ抽屜的效果就可以實現
1.首先在AppDelegate中匯入#import "MMDrawerController.h"
2.//中心檢視
MyTabBarController * myTabBar = [[MyTabBarController alloc]init];
//左邊抽屜
MyViewController * myVC = [[MyViewController alloc]init];
UINavigationController * myNav = [[UINavigationController alloc]initWithRootViewController:myVC];
MMDrawerController * drawerVC = [[MMDrawerController alloc]initWithCenterViewController:self.myTabBar leftDrawerViewController:myNav];
3.在左邊抽屜的ViewController下匯入#import "UIViewController+MMDrawerController.h"
4.UITabBarController * nav = (UITabBarController*)self.mm_drawerController.centerViewController;
UINavigationController *vc = nav.viewControllers[0];
AboutViewController *about = [[AboutViewController alloc]init];
[vc pushViewController:about animated:NO];
[self.mm_drawerController closeDrawerAnimated:YES completion:^(BOOL finished) {
[self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
}];
5.針對不想要左右抽屜手勢的功能,直接實現點選彈出抽屜功能,可以將抽屜的手勢設定為沒有手勢即可
//設定開啟和關閉手勢
drawerVC.openDrawerGestureModeMask = MMOpenDrawerGestureModeNone;
drawerVC.closeDrawerGestureModeMask = MMOpenDrawerGestureModeNone;
(2)使用MMDrawerController以TabBarController為中心檢視,實現左檢視靜態cell可以push到對應介面。
(3)問題:遇到的問題是,當以左抽屜為根檢視push的時候,會出現不能滿屏,center檢視依然存在一部分,解決push滿屏的情況,就需要以center檢視為基礎進行push,但是center檢視主要是NavigationController如果以 UINavigationController * nav = (UINavigationController)self.mm_drawerController.centerViewController;這種方法去接收中心檢視的話,就會出現問題,因為此時的中心檢視TabBarController,用下面程式碼中的方法分部接受中心檢視,就可以實現MMDrawerController抽屜第三方庫可以基於TabBarController實現抽屜。QQ抽屜的效果就可以實現
1.首先在AppDelegate中匯入#import "MMDrawerController.h"
2.//中心檢視
MyTabBarController * myTabBar = [[MyTabBarController alloc]init];
//左邊抽屜
MyViewController * myVC = [[MyViewController alloc]init];
UINavigationController * myNav = [[UINavigationController alloc]initWithRootViewController:myVC];
MMDrawerController * drawerVC = [[MMDrawerController alloc]initWithCenterViewController:self.myTabBar leftDrawerViewController:myNav];
3.在左邊抽屜的ViewController下匯入#import "UIViewController+MMDrawerController.h"
4.UITabBarController * nav = (UITabBarController*)self.mm_drawerController.centerViewController;
UINavigationController *vc = nav.viewControllers[0];
AboutViewController *about = [[AboutViewController alloc]init];
[vc pushViewController:about animated:NO];
[self.mm_drawerController closeDrawerAnimated:YES completion:^(BOOL finished) {
[self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
}];
5.針對不想要左右抽屜手勢的功能,直接實現點選彈出抽屜功能,可以將抽屜的手勢設定為沒有手勢即可
//設定開啟和關閉手勢
drawerVC.openDrawerGestureModeMask = MMOpenDrawerGestureModeNone;
drawerVC.closeDrawerGestureModeMask = MMOpenDrawerGestureModeNone;