我是iOS开发的新手。我正在开发一个使用标签栏控制器的应用程序。我正在以编程方式设置选项卡栏控制器的框架,但是当我切换到iPhone 5时,选项卡栏项目和主视图之间会产生空白。以下是iPhone 5模拟器上的应用程序的屏幕截图。

下面是我为UITabBarController设置框架的代码行
[rootTabBarController.view setFrame:CGRectMake(0,-20,320, 480)];发布于 2013-04-25 20:35:08
just.dont.do.it (不设置帧)!
最简单、最干净的技术是:
YourAppDelegate.h:
@property(nonatomic,retain) UITabBarController * tabBarController;YourAppDelegate.m:
@synthesize tabBarController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
UINavigationController *viewController1 = [[[UINavigationController alloc] initWithRootViewController:[[[UIViewController alloc] init] autorelease]] autorelease];
UINavigationController *viewController2 = [[[UINavigationController alloc] initWithRootViewController:[[[UIViewController alloc] init] autorelease]] autorelease];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.tabBarController.customizableViewControllers = nil;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;}
一切都会好起来的。框架,旋转,自动调整大小,在iPhone,iPad等。
顺便说一句,你可以在Xcode中用"Tab Bar application“模板创建一个新项目,看看Apple是怎么做的
然后..。(建议,将来可以帮助你) UITabBarController必须位于视图层次结构的顶部(直接在UIWindow上)才能正确旋转等,我的示例代码包含了它(它可以为你节省一些将来的时间)
https://stackoverflow.com/questions/16214819
复制相似问题