2

I have an app that's pretty much a large presentation of a companies product.
I have some additional functionality which I need to be accessible throughout my app.

The intended functionality for this toolbar is that it'll sit as a small, subtle tab along the bottom of the screen. When you tap the tab, the menu will expand upward (i.e. animate it's frame.y property), allowing you to tap any of the buttons contained within the menu.

Tab Hidden

Tab Visible

The difficulty I'm having is that the app currently spans over several view controllers, and as I need this accessible throughout, in the interest of not duplicating code it would seem appropriate to make this ViewController also, that I would just load into my other view controllers, but this, by all accounts isn't recommended by Apple.

How can I build this menu functionality without duplicating code? I've tried a few things but cannot get the menu to display on my view.

Below, I'll show what I have at the moment.

Code that will sit on any view controller:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    ToolboxMenu *toolboxMenu = [[ToolboxMenu alloc] init];
    [self.view addSubview:toolboxMenu.view];
}

Code that builds the toolbar:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"Creating View");
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,88,209)];
    self.view.backgroundColor = [UIColor clearColor];

    UIImageView *toolboxImage = [[UIImageView alloc] initWithImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"popup_toolbox" ofType:@"jpg"]]];
    toolboxImage.frame = self.view.frame;
    [self.view addSubview:toolboxImage];

}

In the above code, the NSLog fires when the menu is initialised, but I see no menu.

Dan Hanly
  • 7,829
  • 13
  • 73
  • 134

2 Answers2

2

Rather than try to inject this into every view, I would recommend creating a separate UIWindow and float it over the main UIWindow. This is how the keyboard is implemented. Doing it that way will avoid any changes to any of the existing views. You will need to handle device rotation by hand for it, but that shouldn't be too difficult.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • How would I go about this? Sorry, I'm unsure how to implement another UIWindow. – Dan Hanly Sep 20 '11 at 12:53
  • `self.toolWindow = [[UIWindow alloc] initWithFrame:....]; self.toolWindow.windowLevel = 1.0;` Remember that `UIWindow` is a subclass of `UIView`. – Rob Napier Sep 20 '11 at 14:53
  • 1
    This Answer might be related to this. http://stackoverflow.com/questions/2833724/adding-view-on-statusbar-in-iphone – Sukima Sep 20 '11 at 16:39
0

IIRC Apple's TabViewController was designed differently in that it's backwards to how you describe above. A TabViewController is the main or master ViewController with siblings being the display ViewControlers. Basically you have one TabViewController that will tab between views.

I would recommend you either redesign your view hierarchy OR extend UIViewController with a class that manages and displays the lower tab menu. Then you can easily init a single class that handles that in each of your views.

Sukima
  • 9,965
  • 3
  • 46
  • 60
  • Thanks for your answer. The issue with it is that the full app has been designed and built already without the use of tabs and I just want to add a little view on the bottom right of each screen to handle navigation to the 'toolbox' features. The tab isn't an iPhone SDK tab, it's like a browser tab, but at the bottom of the screen, taking up no more than 20px. Tapping it will raise it and make the menu accessible. – Dan Hanly Sep 20 '11 at 11:38
  • I've added a couple of images in my Original Question that I hope will illustrate this. Does your solution still apply? – Dan Hanly Sep 20 '11 at 12:41
  • Then you would use second option and make the view yourself. @Rob Napir explains the idea better below. – Sukima Sep 20 '11 at 16:37