Frage

Ich habe eine UITabBarController wo die Standard-View-Controller ein UINavigationController ist. Ich möchte in der Lage, die UITabBar der UITabBarController zu verstecken, wenn ich eine bestimmte Ansicht in der UINavigationController drücken.

Ich habe versucht, und fügte hinzu:

delegate.tabBarController.hidesBottomBarWhenPushed = YES;

in meinem UINavigationController bevor ich schiebe die Ansicht, aber das scheint nicht den Trick zu tun.

Irgendwelche Tipps, was soll ich es sogar möglich, zu tun oder wenn sein? Vielen Dank im Voraus!

War es hilfreich?

Lösung

Das ist besser:

viewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:viewController animated:YES];

Sie müssen gesetzt hidesBottomBarWhenPushed = YES auf dem Controller, der Sie in die Ansicht drücken gehen ...

Andere Tipps

, wenn sie mit Storyboard seines einfachen Setup-View-Controller arbeiten, die die Fensterleiste auf Push verstecken, auf den Ziel-View-Controller wählen Sie einfach diese Checkbox:
eingeben Bild Beschreibung hier

Ich habe herausfinden, wie diese gelöst werden, wurde ich in die gleiche Ausgabe läuft, aber Apple sagt uns auch, wie es in der Probe zu tun genannt: „The Elements“ ( http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro. html )

Siehe Funktion unten auf, wie es zu tun, Fügen Sie diese in die init-Funktion der Ansicht, die Sie in schieben wollen!

-(id) init { 
    if(self = [super init]) { 
        self.hidesBottomBarWhenPushed = YES; 
    } 
    return self; 
}

Es wird automatisch die Tabbar wie das Foto-App auf Ihrem iPhone verstecken tun. Und wenn Sie die übergeordnete Ansicht zurück navigieren wird nur die Tabbar zeigt wieder.

Viel Glück

Ich habe die meisten der vorgeschlagenen Lösungen ausprobiert. Am Ende keiner von ihnen für mich gearbeitet.

hideTabBarWhenPushed versteckt die Tab-Leiste nicht nur für die View-Controller, die nächsten geschoben wird, sondern für alle View-Controller, die innerhalb geschoben werden. Für diejenigen, habe ich die Tab-Leiste Controller wollen wieder erscheinen.

Orafaelreis' Lösung (siehe oben) schien Suite, dass die meisten. Aber sein Versuch funktionierte nur für strenge Porträt Orientierungen, auch nicht für den Kopf. So hatte ich es zu reparieren. Das ist, was ich schließlich bekam:

#define kTabBarHeight               49 // This may be different on retina screens. Frankly, I have not yet tried.

- (void) hideTabBar:(BOOL)hide {

    // fetch the app delegate
    AppDelegate         *delegate   = [[UIApplication sharedApplication] delegate];

    // get the device coordinates
    CGRect              bounds      = [UIScreen mainScreen].bounds;
    float               width;
    float               height;

    // Apparently the tab bar controller's view works with device coordinates  
    // and not with normal view/sub view coordinates
    // Therefore the following statement works for all orientations. 
    width                   = bounds.size.width;
    height                  = bounds.size.height;

    if (hide) {

        // The tab bar should be hidden too. 
        // Otherwise it may flickr up a moment upon rotation or 
        // upon return from detail view controllers. 
        [self.tabBarController.tabBar setHidden:YES];

        // Hiding alone is not sufficient. Hiding alone would leave us with an unusable black
        // bar on the bottom of the size of the tab bar. 
        // We need to enlarge the tab bar controller's view by the height of the tab bar. 
        // Doing so the tab bar, although hidden, appears just beneath the screen. 
        // As the tab bar controller's view works in device coordinations, we need to enlarge 
        // it by the tab bar height in the appropriate direction (height in portrait and width in landscape)
        // and in reverse/upside down orientation we need to shift the area's origin beyond zero. 
        switch (delegate.tabBarController.interfaceOrientation) {
            case UIInterfaceOrientationPortrait:
                // Easy going. Just add the space on the bottom.
                [self.tabBarController.view setFrame:CGRectMake(0,0,width,height+kTabBarHeight)];
                break;

            case UIInterfaceOrientationPortraitUpsideDown:
                // The bottom is now up! Add the appropriate space and shift the rect's origin to y = -49
                [self.tabBarController.view setFrame:CGRectMake(0,-kTabBarHeight,width,height+kTabBarHeight)];
                break;

            case UIInterfaceOrientationLandscapeLeft:
                // Same as Portrait but add the space to the with but the height
                [self.tabBarController.view setFrame:CGRectMake(0,0,width+kTabBarHeight,height)];
                break;

            case UIInterfaceOrientationLandscapeRight:
                // Similar to Upside Down: Add the space and shift the rect. Just use x and with this time
                [self.tabBarController.view setFrame:CGRectMake(0-kTabBarHeight,0,width+kTabBarHeight,height)];
                break;

            default:
                break;
        }
    } else {
        // reset everything to its original state. 
        [self.tabBarController.view setFrame:CGRectMake(0,0,width,height)];
        [self.tabBarController.tabBar setHidden:NO];
    }

    return; 
}


- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{

    // It is important to call this method at all and to call it here and not in willRotateToInterfaceOrientation
    // Otherwise the tab bar will re-appear. 
    [self hideTabBar:YES];

    // You may want to re-arrange any other views according to the new orientation
    // You could, of course, utilize willRotateToInterfaceOrientation instead for your subViews. 
}

- (void)viewWillAppear: (BOOL)animated { 

    // In my app I want to hide the status bar and navigation bar too. 
    // You may not want to do that. If so then skip the next two lines. 
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];

    [self hideTabBar: YES];

    // You may want to re-arrange your subviews here. 
    // Orientation may have changed while detail view controllers were visible. 
    // This method is called upon return from pushed and pulled view controllers.   

    return;
}

- (void)viewWillDisappear: (BOOL)animated {     

    // This method is called while this view controller is pulled
    // or when a sub view controller is pushed and becomes visible
    // Therefore the original settings for the tab bar, navigation bar and status bar need to be re-instated

    [self hideTabBar:NO];

    // If you did not change the appearance of the navigation and status bar in viewWillAppear,
    // then you can skip the next two statements too. 
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];

    return;
}

Die in-line Kommentare die Begründung für jede Aussage erklären sollte. Obwohl, kann es intelligentere Wege sei es der Codierung.

Es ist eine Nebenwirkung in Verbindung mit der Statusleiste und Navigationsleiste zu verstecken, was ich will nicht von euch verstecken. 1. Wenn von dieser Navigationssteuerung an die anrufende Navigationssteuerung Rückkehr dann die Statusleiste und Navigationsleiste auf dem anrufenden Controller überlappen, bis das Gerät einmal gedreht wird, oder bis den entsprechenden Registerkarte wieder gewählt worden sind nach der anderen Register nach vorne kam. 2. Wenn der Angerufene-View-Controller eine Tabellenansicht ist und wenn sich das Gerät im Querformat ist, wenn an den Tisch zurückkehrt, dann wird die Tabelle in der geeigneten Orientierung für Landschaft angezeigt, aber es wird legte als wenn es Porträt waren. Die obere linke Ecke ist in Ordnung, aber einige Tabellenzellen und Tab-Leiste unterhalb des Bildschirms versteckt. Auf der rechten Seite gibt es einige freie Raum. Auch dies wird durch Drehen der Vorrichtung wieder fixiert.

Ich halte euch auf dem Laufenden, sobald ich Lösungen für diese kleinen, aber fiesen Bugs gefunden.

Hier ist, wie Sie dies funktioniert:

In der Application Delegate erstellen Sie die UITabBarController. Dann erstellen Sie eine UINavigationController mit Root-Controller als View-Controller Sie in der jeweiligen Registerkarte möchten. Dann legen Sie die UINavigationController in die " Viewcontrollers " Array des UITabBarController. etwa so:

ViewControllerForTab1 *tab1Controller = [[ViewControllerForTab1 alloc] initWithNibName:@"ViewControllerForTab1"];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tab1Controller];

[tab1Controller release];


UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects: navController, nil];

[navController release];


[self.window addSubView:tabBarController.view];

Auf diese Weise können die „hidesBottomBarWhenPushed“ Eigenschaft auf „YES“ in jedem View-Controller innerhalb dieses UINavigationController und es wird Ausblenden der UITabBar einstellen.

Ich hoffe, das hilft!

Ich werde hier meine Lösung für diese lassen:

#define FRAME_HIDDEN CGRectMake(0, 0, 768, 1073) //1073 = 1024 (screen) + 49 (UITabBar) 
#define FRAME_APPEAR CGRectMake(0, 0, 768,1024)

-(void) setHidden: (BOOL) hidden{
    CGRect frame = (hidden)? FRAME_HIDDEN : FRAME_APPEAR;
    [self.tabBarController.view setFrame:frame];
    [self.tabBarController.tabBar setHidden:hidden];
}

Ruft die ‚setHidden‘ Methode, wo Sie es brauchen! Ich Verwendung dieses und das ‚Singleton Pattern‘, dann meine Subviews können die UITabBar in seiner Superview verbergen

Es stellt sich heraus, dass, wenn Sie die Ansicht hidesBottomBarWhenPushed:YES setzen sie die Bar versteckt, wenn die Ansicht (duh auf meiner Seite) erscheint. Ich war es dem UITabBarController zuweisen, die nicht zu viel Sinn macht, wenn man darüber nachdenkt.

[self.view hidesBottomBarWhenPushed:YES];
[super pushViewController:viewController animated:animated];

in dem ersten UIViewController "FirstItemViewController"

 @IBAction func pushToControllerAction(sender: AnyObject) {
     self.hidesBottomBarWhenPushed = true
     self.performSegueWithIdentifier("nextController", sender: self)
 }

in dem nächsten UIViewController "ExampleViewController" `

 override func willMoveToParentViewController(parent: UIViewController?) {
         if parent == nil {
             var viewControllers = self.navigationController!.viewControllers
             if ((viewControllers[viewControllers.count - 2]).isKindOfClass(FirstItemViewController.self)) {
                 (viewControllers[viewControllers.count - 2] as! FirstItemViewController).hidesBottomBarWhenPushed = false
             }
         }
 }

Schauen Sie sich diese Antwort https://stackoverflow.com/a/36148064/3078925

Mit hidesBottomBarWhenPushed in der Steuerung, die Sie ausblenden möchten.

Für ausblenden alle Controller setzen in prepare for segue

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    segue.destination.hidesBottomBarWhenPushed = true
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top