我通过代码添加了一个UINavigationController,但它在顶部留下了差距..大约20 px ..
如果我切换到其他标签然后返回此标签,它就会消失,但在NavBar移动到正确位置之前大约0.2秒可以看到它。
我已经搜索过StackOverflow但我找不到解决方案......
这是我的代码的一部分:
appDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
.....
UIViewController *vc1 = [[Tab1 alloc] initWithNibName:@"Tab1" bundle:nil];
UIViewController *vc2 = [[FreshEpisodeController alloc] initWithNibName:@"FreshEpisodeController" bundle:nil];
UIViewController *vc3 = [[Tab3 alloc] initWithNibName:@"Tab3" bundle:nil];
UIViewController *vc5 = [[DownloadListController alloc] initWithNibName:@"DownloadListController" bundle:nil];
self.tabBarController = [[UITabHost alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:vc2, vc1, vc3, vc5, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
.....
}
Tab3.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[self view] addSubview:mNavController.view];
self.title = NSLocalizedString(@"Collection List", @"Collection List");
self.tabBarItem.image = [UIImage imageNamed:@"tab3"];
}
return self;
}
Tab3.xib中的,我有UIView
和UINavigationController
(mNavController)
如果我将Tab3设置为第一次显示(我把它放在第一个标签页),那么差距不存在 但是,如果我把它放到第二个标签,它显示我是否切换到查看Tab3。
答案 0 :(得分:1)
在 ViewController 的属性部分中将置顶栏属性设置为取消选中可能会有所帮助。
答案 1 :(得分:0)
为视图控制器将“wantsFullScreenLayout”属性设置为“YES”
答案 2 :(得分:0)
尝试这样做
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[self view] addSubview:mNavController.view];
mNavController.view.frame = self.view.bounds; //here you assign the subView frame to fit superView area
self.title = NSLocalizedString(@"Collection List", @"Collection List");
self.tabBarItem.image = [UIImage imageNamed:@"tab3"];
}
return self;
}
答案 3 :(得分:-1)
在UINavigationController (mNavController)
方法中添加viewDidLoad
,代码应如下所示:
- (void)viewDidLoad {
[super viewDidLoad];
[[self view] addSubview:mNavController.view];
self.title = NSLocalizedString(@"Collection List", @"Collection List");
self.tabBarItem.image = [UIImage imageNamed:@"tab3"];
}
现在享受.....