iOS Development Drawer Effect implementation

Source: Internet
Author: User

Said drawer effect in iOS the more famous third-party class library is pprevealsideviewcontroller. When it comes to third-party libraries, it is natural to think of our cocoapods, today's blog with Cocoapods introduced Pprevealsideviewcontroller, and then in our project to code combined with storyboard to make drawer effect.

I. Introduce third-party plug-in Pprevealsideviewcontroller in the project with Cocoapods.

(1). Search for Pprevealsideviewcontroller versions in the terminal

  

(2). Add the appropriate repository in Podfile

(3). Then save the Podfile file and then execute the pod install

Second, add PCH file for our project

Because the use of XCode6, the above default is no PCH file, if we want to use PCH file, need to manually add, add the steps as follows

1. Are there PCH files in XCode6, such as

2. Create a PCH file

    

3. Configuring PCH Files

(1), find the project Targets->build settings->apple LLVM 6.0-language

 

(2) Under Debug and release under Prefix header add $ (srcroot)/project name/pch file, into

    

Third, the use of pprevealsideviewcontroller to achieve drawer effect

Of course. First introduce our third-party class library in the PCH file, then use the

1. In the storyboard drag out the view controller we want to use, click on the main interface button will display the navigation page as a drawer, and then navigate to the various interface in the navigation page, and then back to the main interface from the various pages

2. Initialize our Pprevealsideviewcontroller in Appdelegate and set the code for the startup page as follows:

1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {2     //Override point for customization after application launch.3     4Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];5     6     //get the navigation controller for the main view7Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@"Main"Bundle:[nsbundle Mainbundle]];8Uiviewcontroller *VC = [Storyboard Instantiateviewcontrollerwithidentifier:@"Navigationcontroller"];9     Ten     //Create a new Pprevealsideviewcontroller and set the root view (Navigation view on the main page) OnePprevealsideviewcontroller *sideviewcontroller =[[Pprevealsideviewcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC]; A      -Sideviewcontroller.fakeios7statusbarcolor =[Uicolor Whitecolor]; -      the     //set Sideviewcontroller as the root view controller -Self.window.rootViewController =Sideviewcontroller; -      - [Self.window makekeyandvisible]; +      -     returnYES; +}
View Code

3. Use Pprevealsideviewcontroller to launch the navigation page in the main interface

1-(Ibaction) Tapitem: (ID) Sender {2     3Uistoryboard *storybaord = [Uistoryboard storyboardwithname:@"Main"Bundle:[nsbundle Mainbundle]];4Uitableviewcontroller *table = [Storybaord instantiateviewcontrollerwithidentifier:@"Customviewviewcontroller"];5 [Self.revealsideviewcontroller pushviewcontroller:table ondirection:pprevealsidedirectionleft Animated:YES];6}
View Code

4. Click on the different buttons on the navigation page to use Pprevealsideviewcontroller to jump to a different controller

1-(Ibaction) Tap1: (ID) Sender {2Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@"Main"Bundle:[nsbundle Mainbundle]];3Uiviewcontroller *one = [Storyboard Instantiateviewcontrollerwithidentifier:@" One"];4 [Self.revealsideviewcontroller popviewcontrollerwithnewcentercontroller:one animated:yes];5 }6 7-(Ibaction) TAP2: (ID) Sender {8     9Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@"Main"Bundle:[nsbundle Mainbundle]];TenUiviewcontroller *one = [Storyboard Instantiateviewcontrollerwithidentifier:@" Both"]; One [Self.revealsideviewcontroller popviewcontrollerwithnewcentercontroller:one animated:yes]; A      - } -  the-(Ibaction) TAP3: (ID) Sender { -Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@"Main"Bundle:[nsbundle Mainbundle]]; -Uiviewcontroller *one = [Storyboard Instantiateviewcontrollerwithidentifier:@"three"]; - [Self.revealsideviewcontroller popviewcontrollerwithnewcentercontroller:one animated:yes]; + } -  +-(Ibaction) TAP4: (ID) Sender { AUistoryboard *storyboard = [Uistoryboard storyboardwithname:@"Main"Bundle:[nsbundle Mainbundle]]; atUiviewcontroller *one = [Storyboard Instantiateviewcontrollerwithidentifier:@" Four"]; - [Self.revealsideviewcontroller popviewcontrollerwithnewcentercontroller:one animated:yes]; -}
View Code

5. The code for each page to return to the main interface is as follows:

1-(Ibaction) Tappage: (ID) Sender {2Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@"Main"Bundle:[nsbundle Mainbundle]];3     4Uiviewcontroller *view = [Storyboard Instantiateviewcontrollerwithidentifier:@"Navigationcontroller"];5     6 [Self.revealsideviewcontroller Popviewcontrollerwithnewcentercontroller:view animated:yes];7}
View Code

Four. To achieve this effect, the following are:

iOS Development Drawer Effect implementation

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.