UITabBarController + UISplitviewController 替代品?
Posted
技术标签:
【中文标题】UITabBarController + UISplitviewController 替代品?【英文标题】:UITabBarController + UISplitviewController alternatives? 【发布时间】:2010-12-24 09:39:49 【问题描述】:由于不支持此配置,我想知道人们使用了哪些替代方案。
我有一个通用应用程序,目前在 iPhone 和 iPad 上都使用 4 个选项卡的 UITabBarController。
由于我现在想使用 splitviewcontroller,我面临着一个设计决策。
我想我可以只使用顶部的工具栏并从那里开始,但希望有更多有趣的技术。
【问题讨论】:
[Migrating a tab bar-based iPhone project to iPad ](***.com/questions/3553454/…)的可能副本 可以将 UISplitViewControllers 嵌套在 UITabBarController 中。但是,有一些解决方法是必要的。看我的回答。 【参考方案1】:您可以在 modelViewController 中复制一个 UITabBar,当屏幕底部的按钮被点击并交换视图时,该模型会弹出。 :)
【讨论】:
【参考方案2】:我创建了一个 UITabBarController 子类,它将旋转消息正确地传播到它包含的所有 UISplitViewControllers。这维护了 UISplitViewControllers 的正确内部状态。但是,如果 SplitViewController 不可见,则不会调用其中一个 SplitViewController 委托方法,因此我在详细视图控制器 viewWillAppear 方法中对此进行了说明。我已经确认这适用于 ios5.0 - iOS6.1
AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
OSMasterViewController *masterViewController = [[[OSMasterViewController alloc] initWithNibName:@"OSMasterViewController_iPhone" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
self.window.rootViewController = self.navigationController;
else
OSMasterViewController *masterViewController = [[[OSMasterViewController alloc] initWithNibName:@"OSMasterViewController_iPad" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
OSDetailViewController *detailViewController = [[[OSDetailViewController alloc] initWithNibName:@"OSDetailViewController_iPad" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
masterViewController.detailViewController = detailViewController;
UISplitViewController *splitViewController = [[[OSSplitViewController alloc] init] autorelease];
splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
splitViewController.delegate = detailViewController;
OSTestViewController *secondaryController = [[[OSTestViewController alloc] init] autorelease];
OSTabBarController *tabBarController = [[[OSTabBarController alloc] init] autorelease];
tabBarController.viewControllers = @[self.splitViewController, secondaryController];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
OSTabBarController.m
#import "OSTabBarController.h"
@implementation OSTabBarController
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
for(UIViewController *targetController in self.viewControllers)
if(targetController != self.selectedViewController && [targetController isKindOfClass:[UISplitViewController class]])
[targetController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
for(UIViewController *targetController in self.viewControllers)
if(targetController != self.selectedViewController && [targetController isKindOfClass:[UISplitViewController class]])
[targetController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
@end
DetailViewController
@implementation OSDetailViewController
-(void)viewWillAppear:(BOOL)animated
//the splitViewController:willHideViewController:withBarButtonItem:forPopoverController: may not have been called
if(!UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
self.navigationItem.leftBarButtonItem = nil;
#pragma mark - UISplitViewControllerDelegate Methods
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
@end
【讨论】:
以上是关于UITabBarController + UISplitviewController 替代品?的主要内容,如果未能解决你的问题,请参考以下文章
如何使屏幕仅垂直。 (UITabBarController/Swift)
UITabBarController 上的 WYPopoverController 下降