[英]iOS UITabBarController on 3.5 inch vs 4inch display
我的應用程序啟動時使用LoginViewController
( UIViewController
)來檢查用戶是否已登錄。如果用戶已登錄,則它使用導航控制器來推送其中具有表視圖的taskViewController( UIViewController
)。 它顯示任務列表。
當用戶點擊任務時,它將啟動taskDetailsViewController( UIViewController
),在其中我以編程方式添加了UITabBarController
。
- (void)viewDidLoad
{
[super viewDidLoad];
self.tabBarController = [[UITabBarController alloc] init];
DetailsViewController *detailsViewController = [[DetailsViewController alloc] init];
CommentsViewController *commentsViewController = [[CommentsViewController alloc] init];
FilesViewController *filesViewController = [[FilesViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:detailsViewController, commentsViewController, filesViewController, nil];
self.tabBarController.viewControllers = controllers;
self.tabBarController.selectedIndex = 0;
[self.view addSubview:self.tabBarController.view];
}
這在4英寸顯示屏上可以正常工作,但在3.5英寸顯示屏上,選項卡欄不是底部對齊的,有點向底部浮動。
你知道我在這里做錯什么嗎?
--------------------------------------------
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|------------------------------------------|
| | | |
| Details | Comments | Files |
| | | |
| | | |
|------------------------------------------|
| |
| |
| |
| |
| |
--------------------------------------------
您需要設置布局約束。 對於您的情況,最簡單的方法是創建一個約束,以將到屏幕底部的距離設置為0。例如:
NSDictionary *viewsDictionary =
NSDictionaryOfVariableBindings(self.tabBarController.view);
NSArray *constraints =
[NSLayoutConstraint constraintsWithVisualFormat:@"V:[tabBar]-|"
options:0 metrics:nil views:viewsDictionary];
[self.view addConstraints:constraints];
這表示將標簽欄視圖垂直刷新到屏幕底部。
一般而言, tabBarController
可用作rootViewController
要確定用戶登錄是否成功,請切換rootViewController = tabBarController
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.