iOS开发中抽屉效果的第三方库MMDrawerController的使用

  1 //
  2
  3 // AppDelegate.m
  4
  5 // MMDrawerController
  6
  7 //
  8
  9 // Created by yl on 16/6/24.
 10
 11 // Copyright © 2016年 Itsimple. All rights reserved.
 12
 13 //
 14
 15
 16
 17 #import "AppDelegate.h"
 18
 19 #import "YLNavigationController.h"
 20
 21 #import "YLHomeViewController.h"
 22
 23 #import "YLLeftViewController.h"
 24
 25 #import "MMDrawerController.h"
 26
 27
 28
 29
 30
 31 @interface AppDelegate ()
 32
 33
 34
 35 @end
 36
 37
 38
 39 @implementation AppDelegate
 40
 41
 42
 43
 44
 45 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 46
 47
 48
 49
 50
 51 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
 52
 53
 54
 55 YLNavigationController *centerNav = [[YLNavigationController alloc] initWithRootViewController:[[YLHomeViewController alloc] init]];
 56
 57
 58
 59 YLLeftViewController *leftVC = [[YLLeftViewController alloc] init];
 60
 61
 62
 63 MMDrawerController *mmdc = [[MMDrawerController alloc] initWithCenterViewController:centerNav leftDrawerViewController:leftVC];
 64
 65
 66
 67 [mmdc setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
 68
 69
 70
 71 [mmdc setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
 72
 73
 74
 75 self.window.rootViewController = mmdc;
 76
 77
 78
 79 [self.window makeKeyAndVisible];
 80
 81
 82
 83
 84
 85
 86
 87 return YES;
 88
 89 }
 90
 91
 92
 93 - (void)applicationWillResignActive:(UIApplication *)application {
 94
 95 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
 96
 97 // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
 98
 99 }
100
101
102
103 - (void)applicationDidEnterBackground:(UIApplication *)application {
104
105 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
106
107 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
108
109 }
110
111
112
113 - (void)applicationWillEnterForeground:(UIApplication *)application {
114
115 // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
116
117 }
118
119
120
121 - (void)applicationDidBecomeActive:(UIApplication *)application {
122
123 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
124
125 }
126
127
128
129 - (void)applicationWillTerminate:(UIApplication *)application {
130
131 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
132
133 }
134
135
136
137 @end
  1 //
  2
  3 // YLHomeViewController.m
  4
  5 // MMDrawerController
  6
  7 //
  8
  9 // Created by yl on 16/6/24.
 10
 11 // Copyright © 2016年 Itsimple. All rights reserved.
 12
 13 //
 14
 15
 16
 17 #import "YLHomeViewController.h"
 18
 19 #import "MMDrawerController.h"
 20
 21
 22
 23 @interface YLHomeViewController ()
 24
 25
 26
 27 @end
 28
 29
 30
 31 @implementation YLHomeViewController
 32
 33
 34
 35 - (void)viewDidLoad {
 36
 37 [super viewDidLoad];
 38
 39
 40
 41 [self setNavBar];
 42
 43
 44
 45 }
 46
 47
 48
 49
 50
 51 - (void)setNavBar{
 52
 53
 54
 55 self.view.backgroundColor = [UIColor purpleColor];
 56
 57
 58
 59 self.navigationItem.title = @"Demo";
 60
 61
 62
 63 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"item"] style:0 target:self action:@selector(leftBarButtonItemClick)];
 64
 65 }
 66
 67
 68
 69
 70
 71 - (void)leftBarButtonItemClick{
 72
 73
 74
 75 MMDrawerController *mmdc = (MMDrawerController*)[UIApplication sharedApplication].keyWindow.rootViewController;
 76
 77
 78
 79 [mmdc toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
 80
 81
 82
 83 }
 84
 85
 86
 87
 88
 89 - (void)didReceiveMemoryWarning {
 90
 91 [super didReceiveMemoryWarning];
 92
 93 // Dispose of any resources that can be recreated.
 94
 95 }
 96
 97
 98
 99 /*
100
101 #pragma mark - Navigation
102
103
104
105 // In a storyboard-based application, you will often want to do a little preparation before navigation
106
107 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
108
109 // Get the new view controller using [segue destinationViewController].
110
111 // Pass the selected object to the new view controller.
112
113 }
114
115 */
116
117
118
119
120 @end
  1 //
  2
  3 // YLLeftViewController.m
  4
  5 // MMDrawerController
  6
  7 //
  8
  9 // Created by yl on 16/6/24.
 10
 11 // Copyright © 2016年 Itsimple. All rights reserved.
 12
 13 //
 14
 15
 16
 17 #import "YLLeftViewController.h"
 18
 19 #import "Masonry.h"
 20
 21 #import "YLLoginViewController.h"
 22
 23 #import "MMDrawerController.h"
 24
 25
 26
 27 @interface YLLeftViewController ()
 28
 29
 30
 31 @end
 32
 33
 34
 35 @implementation YLLeftViewController
 36
 37
 38
 39 - (void)viewDidLoad {
 40
 41 [super viewDidLoad];
 42
 43
 44
 45 [self setHeadView];
 46
 47 }
 48
 49
 50
 51
 52
 53 - (void)setHeadView{
 54
 55
 56
 57 self.view.backgroundColor = [UIColor whiteColor];
 58
 59
 60
 61 UIView * headView = [[UIView alloc] init];
 62
 63
 64
 65 headView.frame = CGRectMake(0, 0, self.view.bounds.size.width, [UIScreen mainScreen].bounds.size.height/5);
 66
 67
 68
 69 headView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nav"]];
 70
 71
 72
 73 [self.view addSubview:headView];
 74
 75
 76
 77 UIButton * loginButton = [[UIButton alloc] init];
 78
 79
 80
 81 [headView addSubview:loginButton];
 82
 83
 84
 85 [loginButton setTitle:@"登录" forState:UIControlStateNormal];
 86
 87
 88
 89 [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
 90
 91
 92
 93 [loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
 94
 95
 96
 97 make.top.equalTo(self.view).offset( [UIScreen mainScreen].bounds.size.height/10);
 98
 99 make.left.equalTo(self.view).offset([UIScreen mainScreen].bounds.size.width/5);
100
101 make.width.equalTo(@50);
102
103 make.height.equalTo(@20);
104
105
106
107 }];
108
109
110
111 [loginButton addTarget:self action:@selector(loginButtonClick) forControlEvents:UIControlEventTouchUpInside];
112
113
114
115
116
117 }
118
119
120
121
122
123
124
125 - (void)loginButtonClick{
126
127
128
129 YLLoginViewController * lv = [[YLLoginViewController alloc] init];
130
131
132
133 MMDrawerController * mmdc = (MMDrawerController *)[UIApplication sharedApplication].keyWindow.rootViewController;
134
135
136
137
138
139 [mmdc toggleDrawerSide:MMDrawerSideLeft animated:YES completion:^(BOOL finished) {
140
141
142
143 [(UINavigationController *)mmdc.centerViewController pushViewController:lv animated:YES];
144
145
146
147
148
149 }];
150
151 }
152
153
154
155 - (void)didReceiveMemoryWarning {
156
157 [super didReceiveMemoryWarning];
158
159 // Dispose of any resources that can be recreated.
160
161 }
162
163
164
165
166
167 @end
  1 //
  2
  3 // YLLeftTableViewController.m
  4
  5 // MMDrawerController
  6
  7 //
  8
  9 // Created by yl on 16/6/24.
 10
 11 // Copyright © 2016年 Itsimple. All rights reserved.
 12
 13 //
 14
 15
 16
 17 #import "YLLeftTableViewController.h"
 18
 19 #import "Masonry.h"
 20
 21 #import "YLLoginViewController.h"
 22
 23 #import "MMDrawerController.h"
 24
 25
 26
 27 @interface YLLeftTableViewController ()
 28
 29
 30
 31 @property(nonatomic,weak)UIImageView *iconImage;
 32
 33
 34
 35 @end
 36
 37
 38
 39 @implementation YLLeftTableViewController
 40
 41
 42
 43 - (void)viewDidLoad {
 44
 45 [super viewDidLoad];
 46
 47
 48
 49
 50
 51 [self setHeadView];
 52
 53
 54
 55 }
 56
 57
 58
 59
 60
 61
 62
 63 - (void)setHeadView{
 64
 65
 66
 67 UIView * headView = [[UIView alloc] init];
 68
 69
 70
 71 headView.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, [UIScreen mainScreen].bounds.size.height/5);
 72
 73
 74
 75 self.tableView.tableHeaderView = headView;
 76
 77
 78
 79 self.tableView.tableHeaderView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nav"]];
 80
 81
 82
 83 UILabel *lb = [[UILabel alloc] init];
 84
 85
 86
 87 lb.text = @"用户已登录";
 88
 89
 90
 91 [headView addSubview:lb];
 92
 93
 94
 95 [lb mas_makeConstraints:^(MASConstraintMaker *make) {
 96
 97
 98
 99 make.top.equalTo(self.view).offset( [UIScreen mainScreen].bounds.size.height/10);
100
101 make.left.equalTo(self.view).offset([UIScreen mainScreen].bounds.size.width/5);
102
103 make.width.equalTo(@100);
104
105 make.height.equalTo(@20);
106
107
108
109 }];
110
111
112
113 }
114
115
116
117
118
119 - (void)didReceiveMemoryWarning {
120
121 [super didReceiveMemoryWarning];
122
123
124
125 }
126
127
128
129
130
131
132
133 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
134
135
136
137 return 0;
138
139 }
140
141
142
143 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
144
145
146
147 return 0;
148
149 }
150
151
152
153
154
155
156
157
158 @end
  1 //
  2
  3 // YLLoginViewController.m
  4
  5 // MMDrawerController
  6
  7 //
  8
  9 // Created by yl on 16/6/24.
 10
 11 // Copyright © 2016年 Itsimple. All rights reserved.
 12
 13 //
 14
 15
 16
 17 #import "YLLoginViewController.h"
 18
 19 #import "MMDrawerController.h"
 20
 21 #import "Masonry.h"
 22
 23 #import "YLLeftTableViewController.h"
 24
 25 #import "YLNavigationController.h"
 26
 27 #import "YLHomeViewController.h"
 28
 29
 30
 31 @interface YLLoginViewController ()
 32
 33
 34
 35 @property (nonatomic,strong) UITextField *tf_usename;
 36
 37 @property (nonatomic,strong) UITextField *tf_password;
 38
 39
 40
 41 @end
 42
 43
 44
 45 @implementation YLLoginViewController
 46
 47
 48
 49 - (void)viewDidLoad {
 50
 51 [super viewDidLoad];
 52
 53
 54
 55 [self setNavBar];
 56
 57
 58
 59 [self setSubViews];
 60
 61
 62
 63 }
 64
 65
 66
 67
 68
 69 - (void)setNavBar{
 70
 71
 72
 73 self.navigationItem.title = @"用户登录";
 74
 75
 76
 77 UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"button.png"] style:0 target:self action:@selector(leftItemClick)];
 78
 79
 80
 81 self.navigationItem.leftBarButtonItem = barBtn;
 82
 83
 84
 85 }
 86
 87
 88
 89
 90
 91 - (void)setSubViews{
 92
 93 self.view.backgroundColor = [UIColor whiteColor];
 94
 95 UIButton *loginBtn = [[UIButton alloc] init];
 96
 97 loginBtn.backgroundColor = [UIColor lightGrayColor];
 98
 99 [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
100
101 [loginBtn setBackgroundImage:[UIImage imageNamed:@"nav"] forState:UIControlStateNormal];
102
103 [self.view addSubview:loginBtn];
104
105 [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
106
107 make.top.equalTo(self.view).offset(150);
108
109 make.left.equalTo(self.view).offset(70);
110
111 make.right.equalTo(self.view).offset(-70);
112
113 make.height.equalTo(@35);
114
115 }];
116
117
118
119 [loginBtn addTarget:self action:@selector(loginBtnClick) forControlEvents:UIControlEventTouchUpInside];
120
121
122
123 }
124
125
126
127
128
129 - (void)loginBtnClick{
130
131 YLNavigationController *centerNav = [[YLNavigationController alloc] initWithRootViewController:[[YLHomeViewController alloc] init]];
132
133
134
135 YLLeftTableViewController *leftTableVC = [[YLLeftTableViewController alloc] init];
136
137
138
139 MMDrawerController *mmdc = [[MMDrawerController alloc] initWithCenterViewController:centerNav leftDrawerViewController: leftTableVC];
140
141
142
143 [mmdc setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
144
145
146
147 [mmdc setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
148
149
150
151 UIApplication *application = [UIApplication sharedApplication];
152
153
154
155 application.keyWindow.rootViewController = mmdc;
156
157
158
159 [mmdc toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
160
161
162
163 }
164
165
166
167
168
169 - (void)leftItemClick{
170
171
172
173 MMDrawerController * mmdc = (MMDrawerController *)[UIApplication sharedApplication].keyWindow.rootViewController;
174
175
176
177 [mmdc toggleDrawerSide:MMDrawerSideLeft animated:YES completion:^(BOOL finished) {
178
179
180
181 [(UINavigationController *)mmdc.centerViewController popToRootViewControllerAnimated:YES];
182
183
184
185 }];
186
187
188
189
190
191 }
192
193
194
195
196
197 - (void)didReceiveMemoryWarning {
198
199 [super didReceiveMemoryWarning];
200
201 // Dispose of any resources that can be recreated.
202
203 }
204
205
206
207 /*
208
209 #pragma mark - Navigation
210
211
212
213 // In a storyboard-based application, you will often want to do a little preparation before navigation
214
215 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
216
217 // Get the new view controller using [segue destinationViewController].
218
219 // Pass the selected object to the new view controller.
220
221 }
222
223 */
224
225
226
227
228 @end
 1 //
 2
 3 // YLNavigationController.m
 4
 5 // MMDrawerController
 6
 7 //
 8
 9 // Created by yl on 16/6/24.
10
11 // Copyright © 2016年 Itsimple. All rights reserved.
12
13 //
14
15
16
17 #import "YLNavigationController.h"
18
19
20
21 @interface YLNavigationController ()
22
23
24
25 @end
26
27
28
29 @implementation YLNavigationController
30
31
32
33 - (void)viewDidLoad {
34
35 [super viewDidLoad];
36
37
38
39 [self setNavBar];
40
41
42
43
44
45 }
46
47
48
49 - (void)setNavBar{
50
51
52
53 [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav"] forBarMetrics:UIBarMetricsDefault];
54
55
56
57 self.navigationBar.tintColor = [UIColor whiteColor];
58
59
60
61 [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
62
63 }
64
65
66
67 - (void)didReceiveMemoryWarning {
68
69 [super didReceiveMemoryWarning];
70
71 // Dispose of any resources that can be recreated.
72
73 }
74
75
76
77 /*
78
79 #pragma mark - Navigation
80
81
82
83 // In a storyboard-based application, you will often want to do a little preparation before navigation
84
85 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
86
87 // Get the new view controller using [segue destinationViewController].
88
89 // Pass the selected object to the new view controller.
90
91 }
92
93 */
94
95
96
97
98 @end

时间: 2024-10-27 14:04:05

iOS开发中抽屉效果的第三方库MMDrawerController的使用的相关文章

IOS开发笔记-百度地图(第三方库)

最近做了百度地图,在导入SDK后遇到了一些问题 编译错误: linker command failed with exit code 1 (use -v to see invocation) 想了很多办法,查了很多资料,最后终于解决. 可能原因: 1. 有重复的.m文件,或者未导入 解决办法:有重复的删除即可 在工作左边导航栏Target-->Build Phases-->compile Sources中,第三库库的所有.m文件都添加到里面 2.Valid Architectures 的值 在

侧边栏抽屉效果之开源库MMDrawerController的使用

1.开源库,利用pod引入第三方库MMDrawerController: 在建立的Podfile中加入代码: platform :ios, '7.0' pod 'ReactiveCocoa' pod 'MMDrawerController' pod 'Toast', '~> 3.0' pod 'CocoaSecurity' 其中MMDrawerController就是开源的侧边栏库 2.在appdelegate中加入以下代码 首先加入头文件 #import "AppDelegate.h&q

iOS开发之抽屉效果实现

说道抽屉效果在iOS中比较有名的第三方类库就是PPRevealSideViewController.一说到第三方类库就自然而然的想到我们的CocoaPods,今天的博客中用CocoaPods引入PPRevealSideViewController,然后在我们的工程中以代码结合storyboard来做出抽屉效果. 一.在工程中用CocoaPods引入第三方插件PPRevealSideViewController. (1).在终端中搜索PPRevealSideViewController的版本 (2

iOS开发笔记 - 用CocoaPods管理第三方库

在iOS项目中使用第三方类库可以说是非常常见的事,但是要正确配置这些第三方库会非常的繁琐,还好我们有CocoaPods来做这件事情,就如同在Java的世界里有Maven和Gradle,当然Maven的作用不仅仅是第三依赖库管理.通过CocoaPods工具我们可以为项目添加被称为"Pods"的依赖库(这些类库必须是CocoaPods本身所支持的),并且可以轻松管理其版本. ??CocoaPods意义体现在两个方面.第一,在引入第三方库时它可以自动为我们完成各种各样的配置,包括配置编译阶段

ios开发之 自适应屏九宫格(第三方库Masonry)

转自 http://blog.sina.com.cn/s/blog_13fd67a560102wil5.html //用来记录上一次创建的UILabel UILabel *lastLabel = nil; for (int i = 0; i < 9; i++) { UILabel *label = [UILabel new]; label.textAlignment = NSTextAlignmentCenter; label.text = [NSString stringWithFormat:

iOS中一些 常用的第三方库

转自ibireme的博客 做iOS开发总会接触到一些第三方库,这里整理一下,做一些吐槽. 目前比较活跃的社区仍旧是Github,除此以外也有一些不错的库散落在Google Code.SourceForge等地方.由于Github社区太过主流,这里主要介绍一下Github里面流行的iOS库. 首先整理了一份Github上排名靠前的iOS库(大概600个repos) 除了逛一下每日/每月流行之外,也可以到这里来看一下整个iOS Repos的排名. 下面是一些比较流行的第三方库: HTTP 相比较之下

ios开发中超简单抽屉效果(MMDrawerController)的实现

ios开发中,展示类应用通常要用到抽屉效果,由于项目需要,本人找到一个demo,缩减掉一些不常用的功能,整理出一个较短的实例. 首先需要给工程添加第三方类库 MMDrawerController: 这里讲的实例只加入了左滑抽屉.右滑和左滑只是初始化时多添加一个右视图控制器,其他方法基本相同. 下面是用手势实现抽屉的拉出和收回 1.初始化跟视图控制器时,在AppDelegate中导入头文件 #import "MMDrawerController.h" 2.初始化方法先初始化左视图和中心视

iOS开发中常用第三方库的使用和配置-GDataXML

这篇文章旨在给自己以后需要时能及时的查到,省得每次都去baidu. 1. xml解析库-GDataXML 参考文章:http://blog.csdn.net/tangren03/article/details/7868246 GDataXML下载地址: (1)GDataXML.h/m文件 http://code.google.com/p/gdata-objectivec-client/source/browse/trunk/Source/XMLSupport/ (2)DGataDefines.h

iOS开发中常用的轮子 第四篇 抽屉和侧滑效果

为避免重复造轮子,很多效果和功能都可以从github上找到.清点以前的项目,整理出了很多用过的开源代码,每天奉送一批. 学习例子的方法: 1,了解:运行一遍例子,弄清这些代码的究竟是什么: 2,使用:在之后开发工程中使用这些例子: 3,研究代码:研究例子的代码的实现,简单修改做出自己的效果. 记得要么是facebook,或是twitter第一个使用了个交互效果:而后风靡全球,是产品必用抽屉:再后来就是延生出了各种变形过的效果: 所以,产品经理要你实现抽屉和侧滑效果时,一定要确定到底是什么样抽屉和