国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

IOS中MMDrawerController第三方抽屜效果的基本使用示例

2020-07-26 02:56:29
字體:
來源:轉載
供稿:網友

因為剛開年,所以最近公司比較閑,看到以前并不是我接手的項目中有這種抽屜效果的控制器,比較感興趣,便對MMDrawerController研究起來。也方便自己忘記之后查閱,另外也希望對大家有所幫助(PS:以前都是上面一個導航欄,下面一個tabbar的項目居多,所以對這種抽屜控制器不是很了解).

1.首先,到GitHub上把MMDrawerController下下來,然后倒入到項目中。當然你用cocoapods倒入也行??茨阈那閱hO(∩_∩)O


2.接下來就在appdelegate中擼我們的代碼了。先倒入各個控制器哈。

#import"MMDrawerController.h"#import"rightViewController.h"#import"centerViewController.h"#import"leftViewController.h"#import"MainNavViewController.h"

然后就是在didFinishLaunching中設置相關的控制了,其實跟平時項目的區別就是多了一個抽屜控制器。

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];//左中右三個控制器rightViewController*rightVc = [[rightViewControlleralloc]init];leftViewController*leftVc = [[leftViewControlleralloc]init];centerViewController*centerVc = [[centerViewControlleralloc]init];//導航控制器MainNavViewController*rightNavVc = [[MainNavViewControlleralloc]initWithRootViewController:rightVc];MainNavViewController*leftNavVc = [[MainNavViewControlleralloc]initWithRootViewController:leftVc];MainNavViewController*centerNavVc = [[MainNavViewControlleralloc]initWithRootViewController:centerVc];//抽屜控制器self.mmDrawerController= [[MMDrawerControlleralloc]initWithCenterViewController:centerNavVcleftDrawerViewController:leftNavVcrightDrawerViewController:rightNavVc];//  關閉模式手勢self.mmDrawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;//  打開模式手勢self.mmDrawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;//  抽屜控制器的最長寬度self.mmDrawerController.maximumLeftDrawerWidth = 200;[self.windowmakeKeyAndVisible];self.window.rootViewController=self.mmDrawerController;returnYES;}

其實在這里就已經可以實現抽屜控制器的基本效果的了。但是要如下圖的效果還得加一丟丟代碼。


然后我們在center控制器導航欄的leftBarButton上自定義一個button,添加點擊事件等等,這應該不難哈。記得要導入相關的類。

#import "UIViewController+MMDrawerController.h"- (void)viewDidLoad {  [super viewDidLoad];  // Do any additional setup after loading the view.  self.title = @"Demo";  self.view.backgroundColor = [UIColor greenColor];  //UIBarButtonItem的自定義的分類方法  self.navigationItem.leftBarButtonItem = [UIBarButtonItem initWithTarget:self action:@selector(leftBtnClick) image:@"菜單 (1)" hightImage:@"菜單"];}-(void)leftBtnClick{//  將左邊的控制器打開  [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];}

下面就是left控制器的代碼哈,就是在view上添加了一個tableView。

#import "leftViewController.h"#import "pushViewController.h"#import "UIViewController+MMDrawerController.h"#import "MainNavViewController.h"@interface leftViewController ()<UITableViewDelegate,UITableViewDataSource>@end@implementation leftViewController- (void)viewDidLoad {  [super viewDidLoad];  // Do any additional setup after loading the view.    self.view.backgroundColor = [UIColor blueColor];  UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];  tableView.delegate = self;  tableView.dataSource = self;  [self.view addSubview:tableView];}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{  return 10;}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];  if (cell == nil) {    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];  }  cell.detailTextLabel.text = [NSString stringWithFormat:@"%zd",indexPath.row];  return cell;}

點擊cell跳轉控制器

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{  pushViewController *pushVc = [[pushViewController alloc] init];  pushVc.title = [NSString stringWithFormat:@"%zd",indexPath.row];  //取到center控制器    MainNavViewController *mainNavVc = (MainNavViewController *)self.mm_drawerController.centerViewController;  [mainNavVc pushViewController:pushVc animated:YES];  //關閉了控制器之后記得將模式設置為None  [self.mm_drawerController closeDrawerAnimated:YES completion:^(BOOL finished) {    [self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];  }];}

最后記得在center控制器的viewDidAppear中打開滑動的手勢

-(void)viewDidAppear:(BOOL)animated{  [super viewDidAppear:animated];  [self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南郑县| 贡嘎县| 嘉荫县| 巨野县| 韶关市| 遂宁市| 财经| 南雄市| 洞口县| 正镶白旗| 健康| 盖州市| 桐乡市| 德化县| 马龙县| 栖霞市| 同心县| 东方市| 海安县| 崇文区| 永城市| 河北省| 黑河市| 福清市| 左贡县| 应用必备| 胶州市| 麟游县| 凌海市| 巴彦淖尔市| 孙吴县| 沁源县| 武邑县| 平遥县| 扶绥县| 福建省| 资溪县| 略阳县| 敦化市| 麻栗坡县| 建平县|