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 = [Uicolorwhitecolor];
Uinavigationcontroller * Boutiquenc = [[Uinavigationcontrolleralloc] INITWITHROOTVIEWCONTROLLER:BOUTIQUECVC];
Initialize left view
Leftdrawertableviewcontroller * LEFTTVC =[[leftdrawertableviewcontroller alloc] init];
Uinavigationcontroller * LEFTNC = [[Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:LEFTTVC];
Initializing the drawer View Controller
Mmdrawercontroller * Drawercontroller = [[Mmdrawercontroller alloc]initwithcenterviewcontroller: BOUTIQUENCLEFTDRAWERVIEWCONTROLLER:LEFTNC];
Set the width of the drawer extraction
Drawercontroller.maximumleftdrawerwidth = 200;
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
[Drawercontrollersetopendrawergesturemodemask:mmopendrawergesturemodeall];
[Drawercontrollersetclosedrawergesturemodemask: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];//the way to add the left Drawer control button in Viewdidload
3. Implement the method to add a button below
-(void) Setupleftmenubutton
{
Create button
Mmdrawerbarbuttonitem * Leftdrawerbutton = [[Mmdrawerbarbuttonitemalloc] Initwithtarget:selfaction: @selector ( Leftdrawerbuttonpress:)];
Add Leftbarbuttonitem for Navigationitem
[Self.navigationitem SetLeftBarButtonItem:leftDrawerButtonanimated: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:MMDrawerSideLeftanimated:YES Completion:nil];
}
The implementation of ultra-simple drawer effect (Mmdrawercontroller) in iOS development