Hiding Tabbar while porting from portraid mode to landscape mode in iOS

409 Views Asked by At

I am facing one issue with hiding the UITabBar when moving to landscape view. When I am running my app in Xcode 4.6.1 and iOS 6.1 simulator everything works fine but while running the app in Xcode 5 and iOS 7 simulator I face the following issue.

I am using a tabBarController and 3 tabs are located in it at the bottom of screen. One of the tabs has the functionality to switch from portrait view to landscape view. We need to show the tabBars in portrait view but need to hide them in landscape view. When switching the simulator from portrait to landscape view, tabBar gets hidden but I see a white space at the bottom. It is confirmed that the white space is due to Tabbar because when I changed the hidden property of tabBar to NO

(self.tabBarController.tabBar.hidden = No;)

I can see the tabBars at the place where the white space was coming earlier in landscape view.

I am sharing the code for shouldAutorotateToInterfaceOrientation, where I am creating the landscape view. I have tried to use [UIScreen mainScreen].bounds.size.width instead of self.tabBarController.view.bounds.size.width. Also I have tried hardCoding the value of width, but there is no change in the width of frame.

One more thing to make things clear, If anybody has doubt that why are we removing the landscape view from super view, making it nil and then redrawing it again. This is required because our app shows weekdays - mon, tue, wed and app also supports changing to different language.

So when user selects a different language, we need to show these weekday labels in corresponding language so we have to remove the view and then redraw it again because UILabes do not get refreshed automatically.

I have read some posts on this issue but not able to trace out actual reason. Please if someone has any idea, do suggest a solution.

First , I am creating a landscape view in viewDidLoad() like this -

_landscapeView = [[MyWeekView alloc]initWithFrame:CGRectMake(0, 0, self.tabBarController.view.bounds.size.height, 320)];
[self.view addSubview:_landscapeView];

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    displayEmpName.frame = CGRectMake(0, 22.0, self.tabBarController.view.bounds.size.width, 34.0);
    _portraitView.hidden = YES;
    _landscapeView.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = YES;
    [[self.tabBarController.view.subviews objectAtIndex:0]setFrame:CGRectMake(0, 0, 480,320)];
    dayView.hidden = YES;

    [self.view bringSubviewToFront:_landscapeView];
    self.navigationItem.leftBarButtonItem = nil;


    //LABELS IN SCREEN  DO NOT CHANGE ON CHANGING LANGUAGE
    //RELOAD THE LANDSCAPE VIEW ONCE DEVICE IS CHANGED TO LANDSCAPE MODE

    [_landscapeView removeFromSuperview];
    _landscapeView = nil;
    _landscapeView = [[MyWeekView alloc]initWithFrame:CGRectMake(0, 0,  self.tabBarController.view.bounds.size.width, 320)];
    [self.view addSubview:_landscapeView];
    }
0

There are 0 best solutions below