The tab bar is shifted down outside the borders of the simulator

我只是一个虾纸丫 提交于 2019-12-25 02:15:24

问题


I have created an empty project (XCode 4.2 IOS SDK 5), I have added a new view to it and make it the root view controller inside the appDelegate, so when the app runs, it displays that view correctly, however, I added a tabbarcontroller to the view, created an IBOutlet for it inside the newly created view, and added this line to viewDidLoad method of the view:

[self.view addSubview:self.tabController.view];

so the tab bar loads correctly in the iphone simulator, but with a little problem that I couldn't fix: half of that tab bar is shifted down the simulator which prevents tabs' titles from appearing, exactly as in the following screenshot:

How can I fix this problem?


回答1:


Most likely it's because of status bar. But, because subview where you inserting controller can be any size, most universal solution is:

[tabController.view setFrame:self.view.bounds];

(assuming self.view - is the view, where you adding it)




回答2:


The view with the tab bar on is 480px high, but the view you're adding it to is smaller than that because of the status bar. This means that it starts 22px too low, and ends 22px too low - off the bottom of the screen.

If you want the tab bar to be global to the app link it to an IBOutlet on the app delegate, then do this in your didFinishLaunching method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{    
    // ...

    // Add the tab bar controller's view to the window and display.
    [window addSubview:tabController.view];
    [window makeKeyAndVisible];

    return YES;
}

This adds it to the main window, rather than another view. This will anchor it to the top of the screen, so the bottom will be at the bottom of the screen.



来源:https://stackoverflow.com/questions/8200059/the-tab-bar-is-shifted-down-outside-the-borders-of-the-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!