昨天看陳一發(fā)兒(對(duì),沒錯(cuò),就是那個(gè)穿的最多染坯,開車最快的發(fā)姐电抚,????
)的錄播時(shí),想到了iPad
版本的直播軟件框架闹伪,和UITabbarController + UINavigationController
的通用框架模式不一樣,這里使用UISplitViewController
來實(shí)現(xiàn)相應(yīng)的框架模式,先看一張效果圖
下面開始上代碼,很簡單的
在AppDelegate中的設(shè)置
#import "AppDelegate.h"
#import "MasterViewController.h"
#import "DetailsViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#define Width [UIScreen mainScreen].bounds.size.width
@interface AppDelegate ()
@property (nonatomic,strong) UINavigationController *navigationControllerDetails;
@property (nonatomic,strong) UINavigationController *navigationControllerFirst;
@property (nonatomic,strong) UINavigationController *navigationControllerSecond;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[self setupSpliteViewController];
return YES;
}
#pragma mark 設(shè)置SpliteViewController
- (void)setupSpliteViewController
{
//左側(cè)主視圖
MasterViewController *master = [MasterViewController new];
//右側(cè)默認(rèn)視圖
DetailsViewController *details = [DetailsViewController new];//剛進(jìn)入應(yīng)用默認(rèn)顯示的Controller
self.navigationControllerDetails = [[UINavigationController alloc]initWithRootViewController:details];
FirstViewController *first = [FirstViewController new];
self.navigationControllerFirst = [[UINavigationController alloc]initWithRootViewController:first];
SecondViewController *second = [SecondViewController new];
self.navigationControllerSecond = [[UINavigationController alloc]initWithRootViewController:second];
self.spliteViewController = [[UISplitViewController alloc]init];
self.spliteViewController.viewControllers = @[master,self.navigationControllerDetails,self.navigationControllerFirst,self.navigationControllerSecond];
self.spliteViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;//設(shè)置左側(cè)主視圖Master Controller的顯示模式跋核,現(xiàn)在是一直顯示。如果設(shè)置為橫屏顯示豎屏不顯示叛买,還可以再設(shè)置一下相關(guān)的手勢(shì)屬性砂代,如presentsWithGesture
self.spliteViewController.maximumPrimaryColumnWidth = 128.0f;//調(diào)整左側(cè)主視圖Master Controller的最大顯示寬度
self.window.rootViewController = self.spliteViewController;
}
說明
- DetailsViewController是默認(rèn)顯示的視圖控制器
- MasterViewController是左側(cè)的管理視圖控制器。我們可以在這里面做一些操作率挣,比如切換控制器刻伊,自定義一些視圖。
如下代碼椒功,在MasterViewController中
#import "MasterViewController.h"
@interface MasterViewController ()
@property (nonatomic,strong) UINavigationController *navigationControllerDetails;
@property (nonatomic,copy) NSArray *dataSource;
@end
@implementation MasterViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%@",self.splitViewController.viewControllers);
self.dataSource = self.splitViewController.viewControllers;
}
- (IBAction)changeViewController:(id)sender {
UIButton *btn = (UIButton *)sender;
[self.splitViewController showViewController:self.dataSource[btn.tag] sender:nil];
}
幾乎所有的代碼都在上面了捶箱,你們可以嘗試自己寫一下demo。當(dāng)然动漾,除了我的這種寫法方式丁屎,肯定還會(huì)有別的更好的,希望各位能多多指教谦炬,謝謝了悦屏。