UIView显示边栏的方法

点击主视图中的某个按钮,可以在右侧显示或者隐藏子视图,这种视图布局加载方式可用于,在主视图上需要加载一个子视图,用于对主视图内容的补充说明或者设置。仅支持iOS4以上版本,支持ARC或者Non-ARC。

 

主要是用到了PPRevealSideViewController这个类。下面举一个简单的例子,说明如何使用。

 

AppDelegate.h

 

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, PPRevealSideViewControllerDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) PPRevealSideViewController *revealSideViewController;

@end

 

AppDelegate.m 

 

#import "AppDelegate.h"
#import "MasterViewController.h"

@implementation AppDelegate
@synthesize revealSideViewController = _revealSideViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = PP_AUTORELEASE([[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
    
    MasterViewController *main = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main];
    _revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];
    _revealSideViewController.delegate = self;
    
    self.window.rootViewController = _revealSideViewController;
    
    PP_RELEASE(main);
    PP_RELEASE(nav);
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

@end

 

主视图中的按钮点击执行的方法

 

[self.revealSideViewController pushViewController:self.detailViewController onDirection:PPRevealSideDirectionRight withOffset:240.0f animated:YES];

 

子视图就是一个简单的表格,这里就不赘述了。

 

效果图:


UIView显示边栏的方法

你可能感兴趣的:(ios,iPhone)