Implementation of super simple drawer effect (MMDrawerController) in iOS

Source: Internet
Author: User

Implementation of super simple drawer effect (MMDrawerController) in iOS

In ios development, display applications usually use drawer effects. As a result of project requirements, I found a demo to reduce some of the less commonly used functions and sort out a shorter instance.
First, add a third-party class library to the project.

MMDrawerController:
The examples mentioned here only include the left slide drawer. Right slide and left slide only add one more right view controller during initialization. Other methods are basically the same.

The following figure shows how to pull and withdraw a drawer with a gesture.

1. Import the header file in AppDelegate when initializing the View Controller.

# Import MMDrawerController. h

2. the initialization method first initializes the left and center views, that is,

BoutiqueCollectionViewController

LeftDrawerTableViewController

3. After initializing two sub-view controllers, initialize the drawer Root View Controller MMDrawerController. When initializing the drawer controller, add the left View Controller and central View Controller to the drawer View Controller.

// CollectionView Style
UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];

// Initialize the central view
BoutiqueCollectionViewController * boutiqueCVC = [[BoutiqueCollectionViewController alloc] initWithCollectionViewLayout: flowLayout];
BoutiqueCVC. collectionView. backgroundColor = [UIColor whiteColor];
UINavigationController * boutiqueNC = [[UINavigationController alloc] initWithRootViewController: boutiqueCVC];

// Initialize the Left view
LeftDrawerTableViewController * leftTVC = [[LeftDrawerTableViewController alloc] init];
UINavigationController * leftNC = [[UINavigationController alloc] initWithRootViewController: leftTVC];

// Initialize the drawer View Controller
MMDrawerController * drawerController = [[MMDrawerController alloc] initWithCenterViewController: boutiqueNC leftDrawerViewController: leftNC];

// Set the drawer extract width
DrawerController. maximumLeftDrawerWidth = 200;

4. After Initialization is complete, add a slide gesture to pull out and pull out the drawer through the slide gesture. Gestures are encapsulated in third-party class libraries. The program is as follows.

// Sliding gesture close drawer
[DrawerController setOpenDrawerGestureModeMask: MMOpenDrawerGestureModeAll];
[DrawerController setCloseDrawerGestureModeMask: MMCloseDrawerGestureModeAll];

Self. window. rootViewController = drawerController;

At this point, add the drawer Root View Controller to the window Root View Controller and run the program to control the drawer's pulling and pulling using gestures.



If you need to use a button to control the drawer pulling and pulling back, you need to add the following part.

1. Add the header file to the central View Controller.

# Import UIViewController + MMDrawerController. h // header file encapsulated by a third party
# Import MMDrawerBarButtonItem. h // header file encapsulated by a third party
# Import LeftDrawerTableViewController. h, Left view header file

2. Add the left drawer control button in viewDidLoad.

[Self setupLeftMenuButton]; // Add the left drawer control button in viewDidLoad

3. Add a button below

-(Void) setupLeftMenuButton
{
// Create button
MMDrawerBarButtonItem * leftDrawerButton = [[MMDrawerBarButtonItem alloc] initWithTarget: self action: @ selector (leftDrawerButtonPress :)];

// Add LeftBarButtonItem for navigationItem
[Self. navigationItem setLeftBarButtonItem: leftDrawerButton animated: YES];
}

4. Implement the drawer button action method below.

// Drawer button action
-(Void) leftDrawerButtonPress :( id) sender
{
// Switch the left drawer
[Self. mm_drawerController toggleDrawerSide: MMDrawerSideLeft animated: YES completion: nil];
} Effect display:


 

Related Article

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.