(94) Integrated Pkrevealcontroller for left and right drawer view

Source: Internet
Author: User

Using Pkrevealcontroller can be similar to QQ and other software, such as the left and right drawer view, dragged out of the view is divided into Leftview and Rightview, respectively, from the left half of the view and the second part, so according to different needs, You can choose to use a view as Leftview and Rightview, or you can specify two view.

The basic use steps of this framework are described below.

① download source from GitHub: Pkrevealcontroller

② Import the Source/pkrevealcontroller folder to the project.

③ for convenience, the following code creates the window's root controller, creating the left and right drawer view with storyboard.

1. To create a root controller with code, first remove main from main interface in the project setup.

2. In Appdelegate, import PKRevealController.h, create the root controller, where the default presentation of the controller is called Frontview, the left and right drawers are called Leftview and Rightview respectively.

The ④pkrevealcontroller class method Revealcontrollerwithfrontviewcontroller method has two, one is to create only a single drawer, one is created with two, As long as the Uiviewcontroller is passed in, this shows the view created by Leftview.storyboard as both Leftview and Rightview.

Note that the last root controller should be Revealcontroller.

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {    Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];        Uiviewcontroller *MAINVC = [[Uiviewcontroller alloc] init];    MainVc.view.backgroundColor = [Uicolor whitecolor];        Uistoryboard *SB = [Uistoryboard storyboardwithname:@ "Leftview" bundle:nil];    Uiviewcontroller *LEFTVC = Sb.instantiateinitialviewcontroller;    Uiviewcontroller *RIGHTVC = LEFTVC;        SELF.REVEALVC = [Pkrevealcontroller revealcontrollerwithfrontviewcontroller:mainvc leftViewController:leftVc RIGHTVIEWCONTROLLER:RIGHTVC];        Self.revealVc.delegate = self;        Self.revealVc.animationDuration = 0.25;        Self.window.rootViewController = SELF.REVEALVC;        [Self.window makekeyandvisible];        return YES;    }
It is important to note that storyboard's Instantiateinitialviewcontroller method creates a new uiviewcontroller every time it is called, and cannot be called two times if it is to be shared.

⑤ The purpose of the proxy setting is to listen to the current focus position, Leftview, Frontview, or Rightview, and set the animation interval to set the animation speed for the drawer to unfold and to be closed, and the effect is better.

One such layout of the storyboard on Leftview and Rightview are shown as follows:


The ⑥ implementation Agent method can listen for changes in state:

-(void) Revealcontroller: (Pkrevealcontroller *) Revealcontroller didchangetostate: (pkrevealcontrollerstate) state{        switch (state) {case        Pkrevealcontrollershowsfrontviewcontroller:            NSLog (@ "Show main Window%@", Revealcontroller.frontviewcontroller);            break;        Case Pkrevealcontrollershowsleftviewcontroller:            NSLog (@ "Show left window%@", Revealcontroller.leftviewcontroller);            break;        Case Pkrevealcontrollershowsrightviewcontroller:            NSLog (@ "Show right window%@", Revealcontroller.rightviewcontroller);            break;        Default: Break            ;    }    }

⑦ through the following two methods to achieve the length and retraction of drawers.

/** let the drawer into the display mode, that is,  a longer @param animated whether there is an animation effect @param completion after the completion of the callback */-(void) enterpresentationmodeanimated: ( BOOL) Animated                           completion: (Pkdefaultcompletionhandler) completion;/** If in presentation mode, return to the normal drawer or exit the display. @param entirely if you pass yes, the entire drawer will exit, no will only exit the display mode @param animated whether there is an animation effect @param completion after the completion of the callback */-(void) Resignpresentationmodeentirely: (bool) entirely                              animated: (BOOL) Animated                            completion: ( Pkdefaultcompletionhandler) Completion;
To determine the current owning mode, use the following member properties:

@property (nonatomic, readonly) BOOL ispresentationmodeactive;
The following code changes the drawer mode by getting the Revealviewcontroller by rewriting the touch event to Leftview and Rightview.

Note that you should expose Revealcontroller in appdelegate to get it.

-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{    appdelegate *delegate = [uiapplication Sharedapplication].delegate;    Pkrevealcontroller *REVEALVC = [delegate SHAREDREVEALVC];    if ([REVEALVC ispresentationmodeactive]) {        [REVEALVC resignpresentationmodeentirely:no Animated:yes Completion: Nil];    } else{        [REVEALVC enterpresentationmodeanimated:yes completion:nil];    }    

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

(94) Integrated Pkrevealcontroller for left and right drawer view

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.