iPhone 5 TabBar not functioning in proper position

2019-01-25 05:33发布

I am updating our app and I have added the new default image but my tab bar was not working on the iPhone 5. I did some research and created an if statement checking for the size of the display and then placing the tab bar in the proper location. The problem is that when the if statement hits the iPhone 5 screen size and places the tab bar in the right place, the buttons do not work... If I change the vertical location to a lesser value the buttons then work. Here is the code:

UITabBar *tabBar = self.tabBarController.tabBar;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
        tabBar.frame=CGRectMake(0,431,320,49);
    }
    if(result.height == 568)
    {
        tabBar.frame=CGRectMake(0,519,320,49);
    }
}

Now if I change the "519" vertical alignment to "450" the tab bar is higher up on the screen but the buttons do work. Any ideas -- it's driving me nuts! It's the last thing I need to get working for me to launch my update.

3条回答
相关推荐>>
2楼-- · 2019-01-25 05:54

Check the "Full Screen at Launch" option for your main window in Interface Builder.

enter image description here

If you want to do it without Interface Builder, add

window.frame = [UIScreen mainScreen].bounds;

at the start of your applicationDidFinishLaunching: or application:didFinishLaunchingWithOptions: in the app delegate.

查看更多
劳资没心,怎么记你
3楼-- · 2019-01-25 06:14

This happens due to screen height issue between iPhone 5 and iPhone 4. Add below snippet in AppDelegate file. This solved my problem.

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

  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    
}
查看更多
你好瞎i
4楼-- · 2019-01-25 06:19

If your window is being created in an older nib there is most likely a checkbox that needs to be checked on the windows attributes titled "full screen at launch"

More info here.

查看更多
登录 后发表回答