iOS开发之抽屉效果实现

  说道抽屉效果在iOS中比较有名的第三方类库就是PPRevealSideViewController。一说到第三方类库就自然而然的想到我们的CocoaPods,今天的博客中用CocoaPods引入PPRevealSideViewController,然后在我们的工程中以代码结合storyboard来做出抽屉效果。

  一.在工程中用CocoaPods引入第三方插件PPRevealSideViewController.

    (1).在终端中搜索PPRevealSideViewController的版本

  

    (2).在Podfile中添加相应的版本库

 

    (3).之后保存一下Podfile文件,然后执行pod install即可

 

  二、为我们的工程添加pch文件

    因为用的是XCode6, 上面默认是没有pch文件的,如果我们想使用pch文件,需要手动添加,添加步骤如下

    1.在XCode6中是么有pch文件的,如下图

 

 

    2.创建pch文件

 

    

 

    3.配置pch文件

      (1)、找工程的Targets->Build Settings->Apple LLVM 6.0 - Language

 

      (2)在Prefix Header下面的Debug和Release下添加$(SRCROOT)/工程名/pch文件,入下图

    

  三、使用PPRevealSideViewController来实现抽屉效果

    当然了首先在pch文件中引入我们的第三方类库,然后使用即可

    1.在storyboard拖出来我们要用的视图控制器,点击主界面上的按钮会以抽屉的形式展示出导航页,然后在导航页导航到各个界面,之后在从各个页面回到主界面

 

    2.在AppDelegate中初始化我们的PPRevealSideViewController并设置为启动页面代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    //获取主视图的导航控制器
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];

    //新建PPRevealSideViewController,并设置根视图(主页面的导航视图)
    PPRevealSideViewController *sideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:vc];

    sideViewController.fakeiOS7StatusBarColor = [UIColor whiteColor];

    //把sideViewController设置成根视图控制器
    self.window.rootViewController = sideViewController;

    [self.window makeKeyAndVisible];

    return YES;
}

    3.在主界面使用PPRevealSideViewController来推出导航页

- (IBAction)tapItem:(id)sender {

    UIStoryboard *storybaord = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    UITableViewController *table = [storybaord instantiateViewControllerWithIdentifier:@"CustomViewViewController"];
    [self.revealSideViewController pushViewController:table onDirection:PPRevealSideDirectionLeft animated:YES];
}

    4.在导航页点击不同的按钮使用PPRevealSideViewController跳转到不同的controller

- (IBAction)tap1:(id)sender {
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    UIViewController *one = [storyboard instantiateViewControllerWithIdentifier:@"one"];
    [self.revealSideViewController popViewControllerWithNewCenterController:one animated:YES];
}

- (IBAction)tap2:(id)sender {

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    UIViewController *one = [storyboard instantiateViewControllerWithIdentifier:@"two"];
    [self.revealSideViewController popViewControllerWithNewCenterController:one animated:YES];

}

- (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 {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    UIViewController *one = [storyboard instantiateViewControllerWithIdentifier:@"four"];
    [self.revealSideViewController popViewControllerWithNewCenterController:one animated:YES];
}

 

    5.各个页面返回到主界面的代码如下:

- (IBAction)tapPage:(id)sender {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];

    UIViewController *view = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];

    [self.revealSideViewController popViewControllerWithNewCenterController:view animated:YES];
}

四.到此效果实现完毕,下面是效果图:

 

时间: 2024-10-03 08:27:51

iOS开发之抽屉效果实现的相关文章

iOS实现简易抽屉效果、双边抽屉效果_IOS

本文实例为大家分享了iOS实现抽屉效果的全部代码,供大家参考,具体内容如下 iOS实现简易抽屉效果,代码: @interface ViewController () { UIView* _leftView; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from

ios仿侧边抽屉效果实现代码_IOS

效果图如下 代码实现以及思路下面分析: 代码创建导航控制器 Appdelegate.m中 #import "AppDelegate.h" #import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

iOS实现简单的抽屉效果_IOS

说到抽屉效果在iOS中比较有名的第三方类库就是PPRevealSideViewController.一说到第三方类库就自然而然的想到我们的CocoaPods,本文用CocoaPods引入PPRevealSideViewController,然后在我们的工程中以代码结合storyboard来做出抽屉效果. 一.在工程中用CocoaPods引入第三方插件PPRevealSideViewController. (1).在终端中搜索PPRevealSideViewController的版本 (2).在P

iOS抽屉效果开发案例分享_IOS

本文实例为大家分享了iOS抽屉效果开发实例,供大家参考,具体内容如下 在显示在窗口的控制器上添加三个view(如果只需要往一边滑动就只加2个view) 先声明三个view #import "ViewController.h" @interface ViewController () @property(nonatomic, weak) UIView *mainV; @property(nonatomic, weak) UIView *leftV; @property(nonatomic

iOS开发之路--仿网易抽屉效果_IOS

最终效果图: MainStoryBoard示意图: BeyondViewController.h // // BeyondViewController.h // 19_抽屉效果_仿网易 // // Created by beyond on 14-8-1. // Copyright (c) 2014年 com.beyond. All rights reserved. // #import <UIKit/UIKit.h> #import "LeftTableViewControllerD

iOS中 超简单抽屉效果(MMDrawerController)的实现

ios开发中,展示类应用通常要用到抽屉效果,由于项目需要,本人找到一个demo,缩减掉一些不常用的功能,整理出一个较短的实例. 首先需要给工程添加第三方类库  MMDrawerController:这里讲的实例只加入了左滑抽屉.右滑和左滑只是初始化时多添加一个右视图控制器,其他方法基本相同. 下面是用手势实现抽屉的拉出和收回 1.初始化跟视图控制器时,在AppDelegate中导入头文件 #import "MMDrawerController.h" 2.初始化方法先初始化左视图和中心视

iOS开发之各种动画各种页面切面效果

因工作原因,有段时间没发表博客了,今天就发表篇博客给大家带来一些干货,切勿错过哦.今天所介绍的主题是关于动画的,在之前的博客中也有用到动画的地方,今天就好好的总结一下iOS开发中常用的动画.说道动画其中有一个是仿射变换的概念,至于怎么仿射的怎么变换的,原理如何等在本篇博客中不做赘述.今天要分享的是如和用动画做出我们要做的效果. 今天主要用到的动画类是CALayer下的CATransition至于各种动画类中如何继承的在这也不做赘述,网上的资料是一抓一大把.好废话少说切入今天的正题. 一.封装动画

ios开发-iOS 类型qq侧滑效果导航条不跟着变形

问题描述 iOS 类型qq侧滑效果导航条不跟着变形 开发-iOS 类型qq侧滑效果导航条不跟着变形-导航条跟着屏幕滚动"> 图片中的导航条不跟随这白色视图一起变形 请教下是什么原因 view.sendSubviewToBack(rightView) UIView.animateWithDuration(1) { () -> Void in self.centerVC!.view.center = CGPointMake(UIScreen.mainScreen().bounds.wid

iOS开发中Quartz2D控制圆形缩放和实现刷帧效果_IOS

Quartz2D简要回顾一.什么是Quartz2D  Quartz 2D是⼀个二维绘图引擎,同时支持iOS和Mac系统  Quartz 2D能完成的工作:   绘制图形 : 线条\三角形\矩形\圆\弧等   绘制文字   绘制\生成图片(图像)   读取\生成PDF   截图\裁剪图片   自定义UI控件 二.Quartz2D在iOS开发中的价值 为了便于搭建美观的UI界面,iOS提供了UIKit框架,⾥⾯有各种各样的UI控件 UILabel:显⽰文字 UIImageView:显示图片 UIBu