[英]TabBar and NavigationBar view partly hidden
希望,第三次幸運:
只需嘗試將內容顯示在導航欄下方和標簽欄上方(沒有任何內容,也會顯示在下方)。
我已經嘗試了很多東西,無濟於事。
使用rootController中的以下代碼,我只是想要一個視圖(紅色邊框,以幫助顯示它是否正常工作):
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
UIView *view1 = [[UIView alloc] initWithFrame:self.view.frame];
view1.layer.borderColor = [UIColor redColor].CGColor;
view1.layer.borderWidth = 2.0f;
[self.view addSubview:view1];
}
和設置為:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
TSTFirstViewController *rootController = [[TSTFirstViewController alloc] init];
rootController.title = @"Hello World";
UINavigationController *firstRootController = [[UINavigationController alloc] initWithRootViewController:rootController];
NSArray *viewControllers = @[firstRootController];
UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = viewControllers;
tabBar.tabBar.barStyle = UIBarStyleBlack;
tabBar.tabBar.translucent = NO;
[self.window setRootViewController:tabBar];
[self.window makeKeyAndVisible];
return YES;
}
我明白了:
如果我在AppDelegate
添加兩行:
firstRootController.navigationBar.translucent = NO;
firstRootController.navigationBar.barStyle = UIBarStyleBlack;
一切都變得非常混亂:
紅色邊框向下移動,底部邊框消失在標簽欄下方。 並出現一個大的空白。
如果我刪除半透明線,並添加:
self.edgesForExtendedLayout = UIRectEdgeNone;
進入視圖控制器,我得到:
半透明條,紅色邊框位於導航欄下方的正確位置,但tabBar下方的底部邊框。
我相信我已經嘗試過所有組合和所有想法。
任何人都可以告訴我如何在不使用Interface Builder的情況下在Tab欄上方的導航欄下方放置內容。
提前致謝。
是的,這是您的解決方案。
當您使用self.edgesForExtendedLayout = UIRectEdgeNone;
請考慮在iOS 7中再做三件事
NavigationBar
。 Status Bar
(時間,網絡,電池顯示在上面) TabBar
。 因此,您的實現應從實際視圖高度中減去導航欄,狀態欄和標簽欄的高度。
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height-self.navigationController.navigationBar.frame.size.height-self.navigationController.tabBarController.tabBar.frame.size.height-[UIApplication sharedApplication].statusBarFrame.size.height)];
view1.layer.borderColor = [UIColor redColor].CGColor;
view1.layer.borderWidth = 2.0f;
[self.view addSubview:view1];
這是使用此代碼的附加屏幕。
我希望有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.