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