Я попытался большинство из предложенных решений.В конце концов никто из них не работал для меня.
hideTabBarWhenPushed скрывает панель вкладок не только для контроллера вида, который далее нажимается, но и для всех контроллеров представления, которые вставляются внутри. Для тех, кому я хотел, чтобы контроллер панели вкладок снова появился.
Решение Orafaelreis (см. Выше), казалось, было самым подходящим. Но его попытка работала только на строгие портретные ориентации, даже не перевернутую. Поэтому я должен был исправить это. Это то, что я, наконец, получил:
#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;
}
В комментариях в строке должны быть объяснены причины для каждого утверждения. Хотя, возможно, более разумные способы его кодирования.
Существует один побочный эффект в сочетании со скрытием строки состояния и навигационной панели, что я не хочу скрывать от вас, ребята. 1. При возврате с этого навигационного контроллера на вызывающий навигационный контроллер, строка состояния и панель навигации на вызывающем контроллере перекрываются до тех пор, пока устройство не будет повернуто один раз или пока соответствующая вкладка не будет выбрана снова после того, как другая вкладка выйдет вперед. 2. Когда контроллер вызывающего вида представляет собой представление таблицы и когда устройство находится в ландшафтном режиме при возврате в таблицу, таблица отображается в соответствующей ориентации для пейзажа, но она выкладывается, как если бы это был портрет. Верхний левый угол хорош, но некоторые ячейки таблицы плюс панель вкладок скрыты под экраном. С правой стороны есть некоторое свободное пространство. Это также фиксируется поворотом устройства снова.
Я буду держать вас в курсе, как только я найду решения для этих мелких, но неприятных ошибок.
Это определенно лучше. Спасибо! – givp
Одна вещь, которую следует помнить: вы должны поставить код выше, прежде чем нажимать на контроллер. Это сразу после строки инициализации. Он НЕ будет работать, если вы поместите это в viewDidLoad или подобное место ... – Lukasz
Очень приятно, решено, что часы часов часов !!! – Rahul