开发者

Menu Accessible Throughout My App - How do I code this?

开发者 https://www.devze.com 2023-04-05 22:28 出处:网络
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.

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.

Menu Accessible Throughout My App - How do I code this?

Menu Accessible Throughout My App - How do I code this?

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 th开发者_Go百科e above code, the NSLog fires when the menu is initialised, but I see no menu.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号