分割器目前只支持iPhone6 plus、pad和刚发布的iPhone6s plus。
建立左右两个view。在根视图中:
1 #import "AppDelegate.h" 2 #import "LeftViewController.h" 3 #import "RightViewController.h" 4 @interface AppDelegate () 5 { 6 //声明分割器 7 UISplitViewController *svc; 8 LeftViewController *viewL; 9 RightViewController *viewR; 10 UINavigationController *ncL; 11 UINavigationController *ncR; 12 } 13 @end 14 15 @implementation AppDelegate 16 17 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 18 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 19 // Override point for customization after application launch. 20 self.window.backgroundColor = [UIColor whiteColor]; 21 [self.window makeKeyAndVisible]; 22 23 //创建分割器及两个视图 24 viewL=[[LeftViewController alloc] init]; 25 ncL=[[UINavigationController alloc] initWithRootViewController:viewL]; 26 viewR=[[RightViewController alloc] init]; 27 ncR=[[UINavigationController alloc] initWithRootViewController:viewR]; 28 29 svc=[[UISplitViewController alloc] init]; 30 svc.delegate=self; 31 //设置分割器分割的视图 32 svc.viewControllers=@[ncL,ncR]; 33 self.window.rootViewController=svc; 34 35 return YES; 36 } 37 #pragma mark - 实现分割器协议函数 38 -(BOOL)splitViewController:(UISplitViewController *)splitViewController showViewController:(UIViewController *)vc sender:(id)sender{ 39 return NO; 40 } 41 -(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation{ 42 return NO; 43 }
注意:左边的视图坐标及大小正常取。右边的视图要自适应(判断横屏还是纵屏)
1 tvR=[[UITableView alloc] init]; 2 //判断横屏还是纵屏 3 if (self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation==UIInterfaceOrientationLandscapeRight) { 4 //横屏 5 tvR.frame=CGRectMake(0, 0, 1024-320, 768); 6 }else{ 7 //纵屏 8 tvR.frame=CGRectMake(0, 0, 768, 1024); 9 }
时间: 2024-12-13 17:31:12