PPRevealSideviewController是一个左右移动布局,通俗一点讲就是一个左侧栏工具,功能非常强大,但在使用起来很多人都望洋兴叹,我们慢慢道来吧
先下载PPRevealSideviewController,下载地址
下载下来后有个叫PPRevealSideViewController的项目,打开就是整个demo,demo写得非常强大,这儿主要解释下各个开关的作用。
先看一下图:
每一个开关代表一条属性,我们可以利用这些属性做出各种各样的效果,每个属性代表怎样的效果我就不多解释了,试一下就知道,另一方面属性越多就越复杂,如何快速使用这个第三方框架给我们的项目服务呢,我这里做了一个最简单的demo,只需要几行代码就能实现,先用起来出了效果才有信心慢慢研究,对吧?!
效果图:
关键代码:
AppDelegate.h- //
- // AppDelegate.h
- // Test
- //
- // Created by yusian on 14-6-12.
- // Copyright (c) 2014年 小龙虾论坛. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- @interface AppDelegate : UIResponder <UIApplicationDelegate>
- @property (strong, nonatomic) UIWindow *window;
- @property (strong, nonatomic) PPRevealSideViewController *revealSideViewController;
- @end
复制代码 AppDelegate.m- //
- // AppDelegate.m
- // Test
- //
- // Created by yusian on 14-6-12.
- // Copyright (c) 2014年 小龙虾论坛. All rights reserved.
- //
- #import "AppDelegate.h"
- #import "ViewController.h"
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- // 创建一个窗口
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-
- // 创建一个主控制器
- ViewController *viewController = [[ViewController alloc] init];
-
- // 创建一个导航控制器
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
-
- // 创建一个侧栏控制器
- self.revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];
-
- // 侧栏控制器设置为主控制器
- self.window.rootViewController = self.revealSideViewController;
-
- // 将当前窗口设为可见
- [self.window makeKeyAndVisible];
-
- return YES;
- }
-
- - (void)applicationWillResignActive:(UIApplication *)application
- {
- // 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.
- // 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.
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application
- {
- // 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.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
- // 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.
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- // 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.
- }
- - (void)applicationWillTerminate:(UIApplication *)application
- {
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- }
- @end
复制代码 ViewController.h- //
- // ViewController.h
- // Test
- //
- // Created by yusian on 14-6-12.
- // Copyright (c) 2014年 小龙虾论坛. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- @interface ViewController : UIViewController
- @end
复制代码 VIewController.m- //
- // ViewController.m
- // Test
- //
- // Created by yusian on 14-6-12.
- // Copyright (c) 2014年 小龙虾论坛. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- // 设置主页背景颜色为蓝色
- self.view.backgroundColor = [UIColor blueColor];
-
- // 添加导航左侧按钮
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftButton:)];
- }
- #pragma mark 导航左侧按钮事件
- - (void)clickLeftButton:(UIBarButtonItem *)leftButton
- {
- // 创建一个控制器并将控制器背景色设置为红色
- UIViewController *left = [[UIViewController alloc] init];
- left.view.backgroundColor = [UIColor redColor];
-
- // 展示左侧控制器
- [self.revealSideViewController pushViewController:left onDirection:PPRevealSideDirectionLeft animated:YES];
- }
- @end
复制代码
源代码下载:
游客,本帖隐藏的内容需要积分高于 1 才可浏览,您当前积分为 0 |