Problem Hiding Tab Bar

Discussion in 'iOS Programming' started by RagingGoat, Aug 12, 2013.

  1. RagingGoat macrumors 6502

    Joined:
    Jun 21, 2010
    #1
    My app has a tab bar controller and a web view controller. On the web view I am using a tap gesture to hide/show the navigation bar, status bar, and tab bar in order to give the user the option to view the web view in full screen. Everything seems to work except the tab bar leaves behind a black rectangle where the tab bar was. How can I get my web view to utilize that space?

    Code:
    
    #import "WebViewController.h"
    #import "TUSafariActivity.h"
    #import "SVProgressHUD.h"
    #import "KFBAppDelegate.h"
    
    @implementation WebViewController
    @synthesize webView=webView, hackyURL=hackyURL;
    
    - (void)loadView
    {
        // Create an instance of UIWebView as large as the screen
        CGRect screenFrame = [[UIScreen mainScreen]applicationFrame];
        UIWebView *wv = [[UIWebView alloc]initWithFrame:screenFrame];
        webView = wv;
        NSLog(@"%@",webView.request.URL);
        // Tell web view to scale web content to fit within bounds of webview
        [wv setScalesPageToFit:YES];
        
        [self setView:wv];
    }
    
    - (UIWebView *)webView
    { 
        return (UIWebView *)[self view];
    }
    
    - (void) showMenu
    {  
        NSURL *urlToShare = hackyURL;
        NSArray *activityItems = @[urlToShare];
        TUSafariActivity *activity = [[TUSafariActivity alloc] init];
        
        __block UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:@[activity]];
        activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];
        
        [self presentViewController:activityVC animated:YES completion:^{activityVC.excludedActivityTypes = nil; activityVC = nil;}];
    }
    
    - (void)toggleBars:(UITapGestureRecognizer *)gesture
    {
        // KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
        
        if (([UIApplication sharedApplication].statusBarHidden = YES))
        {
            [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
        }
        else
        {
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
        }
        
        BOOL barsHidden = self.navigationController.navigationBar.hidden;
        [self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
        
        BOOL tabBarHidden = self.tabBarController.tabBar.hidden;
        [self.tabBarController.tabBar setHidden:!tabBarHidden];
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
        
        UIBarButtonItem *systemAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showMenu)];
        self.navigationItem.rightBarButtonItem = systemAction;
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toggleBars:)];
        [webView addGestureRecognizer:singleTap];
        singleTap.delegate = self;
    }
    
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    {
        return YES;
    }
    
    @end
    
     
  2. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #2
    UITabBarController and UINavigationController will both always do their best to be top most in the view hierarchy. Even though you have hidden the tab bar itself your actual view is below the tabbar.

    The often suggested approach to get full screen is to stick your full screen view directly onto the UIApplication's window. Instead consider presenting a viewcontroller containing your view modally. A modal viewcontroller will take fullscreen over a UINavigationController and UITabBarController.
     

Share This Page