Я написал свой. Ключ заключается в том, чтобы создать подкласс UIViewController
И не забудьте установить self.title и значок для его первого «содержащегося» класса, иначе ничто не будет отображаться на tabBarIcons. UINavigationController
- это только один уровень глубины от UIViewController
, так что вы можете просмотреть заголовок и легко увидеть, что он реализует, но это были единственные реальные ключи, которые «копируют».
В Interface Builder
, предполагая, что у вас есть перо, чтобы сделать его вместе, создайте основной вид размером экрана (311, если у вас есть tabBar и Status Bar), затем создайте вид сверху, который IB-outletted быть панелью навигации и нижним видом, который выводится как контейнер. Затем сделайте что-то вроде этого:
примечание: я испортил центральную точку, так как столкнулся с множеством проблем, связанных с попыткой перемещения видов без смещения их на высоту пикселя, хотя я знаю об относительном расположении подпредставлений, он просто не работал для по какой-то причине, даже если двигаться только в сторону
Я публикую этот код, потому что никто, похоже, не имеет такого типа вещей. Это может помочь кому-то или даже больше.
Стивен Джонсон.
импорт "CustomNavigationController.h"
@implementation CustomNavigationController
@synthesize backgroundImg, title1, title2, title3;
- (id) initWithRootViewController:(UIViewController*)c;
{
self = [super initWithNibName:nil bundle:nil];
if (self) {
containedControllers = [[NSMutableArray alloc] initWithObjects:c, nil];
self.title1.text = c.title; //a custom outlet for text of title, resembling the NavigationController's title basically
[container addSubview:c.view];
c.view.frame = container.bounds;
back.hidden = YES; //backbutton
c.customNavigationController = self;
self.title = c.title;
self.tabBarItem.image = c.tabBarItem.image;
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void) dealloc;
{
[containedControllers removeAllObjects];
[containedControllers release];
[super dealloc];
}
- (void) pushViewController:(UIViewController*)v animated:(BOOL)a;
{
float w = container.frame.size.width;
float h = container.frame.size.height;
[containedControllers addObject:v];
[self.view addSubview:v.view];
// v.view.frame = CGRectMake(w,0,w,h);
v.view.frame = container.bounds;
v.view.center = CGPointMake(v.view.center.x + w, v.view.center.y + container.frame.origin.y);
v.customNavigationController = self;
float time = a ? 0.31 : 0;
UIViewController * lastViewController = nil;
lastViewController = (UIViewController*)[containedControllers lastObject];
[UIView animateWithDuration:time animations:^{
for (UIViewController * c in containedControllers) {
// c.view.frame = CGRectMake(c.view.frame.origin.x + w*direction, 0, w, h);
c.view.center = CGPointMake(c.view.center.x + w*-1, c.view.center.y);
}
} completion:^(BOOL finished) {
self.title1.text = v.title;
back.hidden = NO;
}];
}
- (void) popViewControllerAnimated:(BOOL)a;
{
float w = container.frame.size.width;
float h = container.frame.size.height;
float time = a ? 0.31 : 0;
float direction = 1;
[UIView animateWithDuration:time animations:^{
for (UIViewController * c in containedControllers) {
// c.view.frame = CGRectMake(c.view.frame.origin.x + w*direction, 0, w, h);
c.view.center = CGPointMake(c.view.center.x + w*direction, c.view.center.y);
}
} completion:^(BOOL finished) {
// lastViewController = (UIViewController*)[containedControllers lastObject];
[containedControllers removeLastObject];
self.title1.text = ((UIViewController*)[containedControllers lastObject]).title;
if ([containedControllers count] > 1) {
back.hidden = NO;
}
else
back.hidden = YES;
}];
}
- (IBAction) popLastVC;
{
[self popViewControllerAnimated:YES];
}
@end