In iOS development, the display class application usually uses the drawer effect, because the project needs, I found a demo, reduced some infrequently used functions, organized a shorter instance.
First you need to add a third-party class library to your project
Mmdrawercontroller:
The example here is only added to the left slide drawer. The right and left slides are just the same as adding a right view controller when initializing, and the other methods are basically the same.
The following is a gesture to achieve the drawer pull and retract
1. When initializing with the view controller, import the header file in Appdelegate
#import "MMDrawerController.h"
2. The initialization method first initializes the left and center views, which are the
Boutiquecollectionviewcontroller
Leftdrawertableviewcontroller
3. After initializing two sub-view controllers, initialize the drawer root view controller Mmdrawercontroller, the left view controller and the central view controller need to be added to the drawer view controller when the drawer controller is initialized.
the style of the//collectionview
uicollectionviewflowlayout * FlowLayout = [[Uicollectionviewflowlayout alloc] init];
//Initialize Center view
Boutiquecollectionviewcontroller * BOUTIQUECVC = [[Boutiquecollectionviewcontroller alloc] Initwithcollectionviewlayout:flowlayout];
BoutiqueCVC.collectionView.backgroundColor = [Uicolor Whitecolor];
Uinavigationcontroller * Boutiquenc = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:BOUTIQUECVC];
//Initialize left view
Leftdrawertableviewcontroller * LEFTTVC = [[Leftdrawertableviewcontroller alloc] init];
Uinavigationcontroller * LEFTNC = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:LEFTTVC];
//Initialize the drawer view controller
Mmdrawercontroller * Drawercontroller = [[Mmdrawercontroller alloc] Initwithcenterviewcontroller:boutiquenc LeftD RAWERVIEWCONTROLLER:LEFTNC];
Set the width of the drawer extraction
drawercontroller.maximumleftdrawerwidth = $;
4. After the initialization is complete, add a swipe gesture to pull and retract the drawer by swiping. Gestures are encapsulated in a third-party class library with the following procedures.
//Swipe gesture quick close drawer
[Drawercontroller Setopendrawergesturemodemask:mmopendrawergesturemodeall];
[Drawercontroller Setclosedrawergesturemodemask:mmclosedrawergesturemodeall];
Self.window.rootViewController = Drawercontroller;
to this, the drawer root view controller is added to the window's root view controller, running the program, you can use gestures to control the drawer pull and retract.
If you need to use a button to control pull and retract drawers, add the following section.
1. Add a header file to the Hub view controller
#import "Uiviewcontroller+mmdrawercontroller.h"//third-party encapsulated header files
#import "MMDrawerBarButtonItem.h"//third-party encapsulated header files
#import "LeftDrawerTableViewController.h", and left view header file
2. How to add the left Drawer control button in Viewdidload
[self Setupleftmenubutton];//Implement the method of adding left Drawer control button in Viewdidload
3. Implement the method to add a button below
-(void) Setupleftmenubutton
{
//Create button
Mmdrawerbarbuttonitem * Leftdrawerbutton = [[Mmdrawerbarbuttonitem alloc] initwithtarget:self action: @selector (le Ftdrawerbuttonpress:)];
//Add Leftbarbuttonitem for Navigationitem
[Self.navigationitem Setleftbarbuttonitem:leftdrawerbutton animated:yes];
}
4. Implement the action method of the drawer button below.
//Drawer button action
-(void) leftdrawerbuttonpress: (ID) Sender
{
//Switch left drawer
[Self.mm_drawercontroller toggledrawerside:mmdrawersideleft animated:yes Completion:nil];
}Effect Show:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The implementation of ultra-simple drawer effect (Mmdrawercontroller) in iOS