年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2964|回复: 0

PPRevealSideviewController快速入门

[复制链接]
  • TA的每日心情
    奋斗
    2022-12-13 21:26
  • 签到天数: 371 天

    [LV.9]以坛为家II

    发表于 2014-6-12 10:48:00 | 显示全部楼层 |阅读模式
    PPRevealSideviewController是一个左右移动布局,通俗一点讲就是一个左侧栏工具,功能非常强大,但在使用起来很多人都望洋兴叹,我们慢慢道来吧

    先下载PPRevealSideviewController,下载地址

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

    先看一下图:

    iOS 模拟器屏幕快照“2014年6月12日 上午10.36.34”.png    iOS 模拟器屏幕快照“2014年6月12日 上午10.36.37”.png

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

    效果图:

    iOS 模拟器屏幕快照“2014年6月12日 上午10.30.45”.png    iOS 模拟器屏幕快照“2014年6月12日 上午10.30.49”.png

    关键代码:

    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
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-5-3 21:00 , Processed in 0.050874 second(s), 24 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表