分享

PPRevealSideviewController快速入门

 爽行天下丶 2015-06-26


PPRevealSideviewController是一个左右移动布局,通俗一点讲就是一个左侧栏工具,功能非常强大,但在使用起来很多人都望洋兴叹,我们慢慢道来吧

先下载PPRevealSideviewController,下载地址

下载下来后有个叫PPRevealSideViewController的项目,打开就是整个demo,demo写得非常强大,这儿主要解释下各个开关的作用。

先看一下图:

  

每一个开关代表一条属性,我们可以利用这些属性做出各种各样的效果,每个属性代表怎样的效果我就不多解释了,试一下就知道,另一方面属性越多就越复杂,如何快速使用这个第三方框架给我们的项目服务呢,我这里做了一个最简单的demo,只需要几行代码就能实现,先用起来出了效果才有信心慢慢研究,对吧?!

效果图:

  

关键代码:

AppDelegate.h
  1. //
  2. //  AppDelegate.h
  3. //  Test
  4. //
  5. //  Created by yusian on 14-6-12.
  6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
  7. //

  8. #import <UIKit/UIKit.h>

  9. @interface AppDelegate : UIResponder <UIApplicationDelegate>

  10. @property (strong, nonatomic) UIWindow *window;

  11. @property (strong, nonatomic) PPRevealSideViewController *revealSideViewController;

  12. @end
复制代码

AppDelegate.m
  1. //
  2. //  AppDelegate.m
  3. //  Test
  4. //
  5. //  Created by yusian on 14-6-12.
  6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
  7. //

  8. #import "AppDelegate.h"
  9. #import "ViewController.h"

  10. @implementation AppDelegate

  11. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  12. {
  13.     // 创建一个窗口
  14.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  15.    
  16.     // 创建一个主控制器
  17.     ViewController *viewController = [[ViewController alloc] init];
  18.    
  19.     // 创建一个导航控制器
  20.     UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
  21.    
  22.     // 创建一个侧栏控制器
  23.     self.revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];
  24.    
  25.     // 侧栏控制器设置为主控制器
  26.     self.window.rootViewController = self.revealSideViewController;
  27.    
  28.     // 将当前窗口设为可见
  29.     [self.window makeKeyAndVisible];
  30.    
  31.     return YES;
  32. }
  33.                                                         
  34. - (void)applicationWillResignActive:(UIApplication *)application
  35. {
  36.     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  37.     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
  38. }

  39. - (void)applicationDidEnterBackground:(UIApplication *)application
  40. {
  41.     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  42.     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  43. }

  44. - (void)applicationWillEnterForeground:(UIApplication *)application
  45. {
  46.     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
  47. }

  48. - (void)applicationDidBecomeActive:(UIApplication *)application
  49. {
  50.     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  51. }

  52. - (void)applicationWillTerminate:(UIApplication *)application
  53. {
  54.     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  55. }

  56. @end
复制代码

ViewController.h
  1. //
  2. //  ViewController.h
  3. //  Test
  4. //
  5. //  Created by yusian on 14-6-12.
  6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
  7. //

  8. #import <UIKit/UIKit.h>

  9. @interface ViewController : UIViewController

  10. @end
复制代码

VIewController.m
  1. //
  2. //  ViewController.m
  3. //  Test
  4. //
  5. //  Created by yusian on 14-6-12.
  6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
  7. //

  8. #import "ViewController.h"

  9. @interface ViewController ()

  10. @end

  11. @implementation ViewController

  12. - (void)viewDidLoad
  13. {
  14.     [super viewDidLoad];
  15.    
  16.     // 设置主页背景颜色为蓝色
  17.     self.view.backgroundColor = [UIColor blueColor];
  18.    
  19.     // 添加导航左侧按钮
  20.     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftButton:)];
  21. }

  22. #pragma mark 导航左侧按钮事件
  23. - (void)clickLeftButton:(UIBarButtonItem *)leftButton
  24. {
  25.     // 创建一个控制器并将控制器背景色设置为红色
  26.     UIViewController *left = [[UIViewController alloc] init];
  27.     left.view.backgroundColor = [UIColor redColor];
  28.    
  29.     // 展示左侧控制器
  30.     [self.revealSideViewController pushViewController:left onDirection:PPRevealSideDirectionLeft animated:YES];
  31. }

  32. @end
复制代码


源代码下载:
游客,本帖隐藏的内容需要积分高于 1 才可浏览,您当前积分为 0

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多