Ho provato la maggior parte delle soluzioni proposte.Alla fine nessuno di loro ha funzionato per me.
hideTabBarWhenPushed nasconde la barra delle schede non solo per il controller di visualizzazione che viene premuto successivamente ma per tutti i controller di visualizzazione inseriti all'interno. Per quelli che volevo che il controller della barra delle schede riapparisse.
La soluzione di Orafaelreis (vedi sopra) sembrava essere la soluzione più adatta. Ma il suo tentativo ha funzionato solo per rigidi orientamenti di ritratto, nemmeno per capovolgere. Quindi ho dovuto ripararlo. Questo è quello che ho finalmente ottenuto:
#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;
}
I commenti in linea dovrebbero spiegare il ragionamento per ogni affermazione. Tuttavia, potrebbero esserci modi più intelligenti di codificarlo.
C'è un effetto collaterale in congiunzione con nascondere anche la barra di stato e la barra di navigazione, che non voglio nascondere a voi ragazzi. 1. Quando si torna da questo controller di navigazione al controller di navigazione chiamante, la barra di stato e la barra di navigazione sul controller chiamante si sovrappongono fino a quando il dispositivo non viene ruotato una volta o fino a quando la relativa scheda non viene nuovamente selezionata dopo un'altra scheda. 2. Quando il controller della vista chiamante è una vista tabella e quando il dispositivo è in modalità orizzontale quando si torna alla tabella, la tabella viene visualizzata nell'orientamento appropriato per l'orizzontale, ma viene disposta come se fosse ritratto. L'angolo in alto a sinistra va bene, ma alcune celle della tabella più una barra delle schede sono nascoste sotto lo schermo. Sul lato destro c'è dello spazio libero. Anche questo viene risolto ruotando nuovamente il dispositivo.
Ti terrò aggiornato una volta trovata le soluzioni per questi bug minori ma sgradevoli.
Questo è decisamente meglio. Grazie! – givp
Una cosa da ricordare: è necessario inserire il codice sopra PRIMA di spingerlo sul controller. Questo è subito dopo la linea di inizializzazione. Non funzionerà se lo metti in viewDidLoad o in un luogo simile ... – Lukasz
Molto bello, ho risolto le mie ore ore di lavoro !!! – Rahul