Mmdrawercontroller practice, has been implemented, a few lines of simple code implementation sidebar

Source: Internet
Author: User

Learning methods, read the Readme, see the Demo

See the function how to achieve the imitation, personal feeling imitation is the fastest way to learn

Nonsense less say on the code

Import Mmdrawercontroller Framework I don't have much, then what we do is what we focus on.

First introduce the framework of the basic mechanism, the framework has a center, around three controller so to create three controller, three controllers placed in the frame at the specified location, see Code Understanding


#import "AppDelegate.h"

Drawer effect
#import "MMDrawerController.h"

Center View
#import "CenterViewController.h"

Left view
#import "LeftViewController.h"

Right view
#import "RightViewController.h"

Navigation bar, where you need to be aware, because, if you set only one-controller, the navigation bar will not move with the controller
#import "NaviViewController.h"

This is the same file as the reveal Image monitor, and the specific configuration is then attached to the article
#import <dlfcn.h>
@interface Appdelegate ()

Upgrade drawer effect to properties, global hold
@property (Nonatomic,strong) Mmdrawercontroller *drawer;
@end

@implementation Appdelegate

Image display
-(void) loadreveal
{
if (nsclassfromstring (@ "ibarevealloader") = = nil)
{
NSString *reveallibname = @ "Libreveal";
NSString *reveallibextension = @ "Dylib";
NSString *error;
NSString *dylibpath = [[NSBundle mainbundle] Pathforresource:reveallibname oftype:reveallibextension];

if (dylibpath! = nil)
{
NSLog (@ "Loading Dynamic Library:%@", Dylibpath);
void *reveallib = Dlopen ([Dylibpath cstringusingencoding:nsutf8stringencoding], rtld_now);

if (reveallib = = NULL)
{
Error = [NSString stringwithutf8string:dlerror ()];
}
}
Else
{
Error = @ "File not found.";
}

if (Error! = nil)
{
NSString *message = [NSString stringwithformat:@ "%@.%@ failed to load with error:%@", Reveallibname, Reveallibextension, ERROR];
[[[Uialertview alloc] initwithtitle:@ "Reveal library could not being loaded" Message:message Delegate:nil cancelbuttontitle : @ "OK" otherbuttontitles:nil] show];
}
}
}

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {
Override point for customization after application launch.

Uiviewcontroller *left = [Leftviewcontroller new];
Left.view.backgroundColor = [Uicolor Whitecolor];
Uiviewcontroller *right = [Rightviewcontroller new];
Uinavigationcontroller *leftnavi = [[Uinavigationcontroller alloc]initwithrootviewcontroller:left];
Uinavigationcontroller*rightnavi = [[Uinavigationcontroller alloc]initwithrootviewcontroller:right];
Right.view.backgroundColor = [Uicolor Redcolor];
Uiviewcontroller *center = [Centerviewcontroller new];
Uinavigationcontroller *centernavi = [[Naviviewcontroller alloc]initwithrootviewcontroller:center];

I've only implemented the left column here.
self.drawer = [[Mmdrawercontroller Alloc]initwithcenterviewcontroller:centernavi Leftdrawerviewcontroller: Leftnavi Rightdrawerviewcontroller:nil];

Center.view.backgroundColor = [Uicolor Bluecolor];
Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];

Set the Shadow Effect
[Self.drawer Setshowsshadow:no];

Set the width of the left column when open
[Self.drawer setmaximumleftdrawerwidth:100];

Turn on the left hand side of the gesture, the gesture is the frame's own direct use, can be customized. Reference to the original framework of the Readme implementation
[Self.drawer Setopendrawergesturemodemask:mmopendrawergesturemodeall];

Turn off gestures
[Self.drawer Setclosedrawergesturemodemask:mmclosedrawergesturemodeall];



Uicolor * Tintcolor = [Uicolor colorwithred:29.0/255.0
green:173.0/255.0
blue:234.0/255.0
ALPHA:1.0];
[Self.window Settintcolor:tintcolor];
[Self.window SetRootViewController:self.drawer];

Call Image Monitoring
[Self loadreveal];
return YES;
}

Here's a look at a navigation situation, well, it's almost impossible to see,

Demo Address: Https://github.com/lizhaojie001/Drawer.git

---restore content ends---

Mmdrawercontroller practice, has been implemented, a few lines of simple code implementation sidebar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.