Remove the toolbar when clicking a new view

The iPhone maps application has a toolbar at the bottom of the map (it contains the Search / Directions control and others). When you move from the map screen by clicking on the leader, the toolbar opens with a map view, leaving the next view (table controller) without a toolbar.

I tried to do the same with [self.navigationController setToolbarHidden:YES animated:YES]the second view controller, but this gives a weird, plugin animation of the toolbar while the map display shifts to the left.

Using [self.navigationController setToolbarHidden:YES]in viewDidLoadalso causes a bad effect (this makes the panel disappear the moment the push animation starts, leaving an ugly empty space).

I assume the answer to this question is to use the nib file, but I would prefer to do it programmatically (if possible).

How can I make the toolbar “stick” to the map view and slip out with it when I click on the new view controller? Thank.

Gourmet Haus Staudt http://img.skitch.com/20100518-xfubyriig48d3ckaemjg2ay8q.jpg

+3
source share
3 answers

It turns out that you need to create a toolbar directly and add it to the view yourself. This is in the code for UIViewControllers UINavigationController. The frame coordinates may vary depending on what is on the screen.

- (void)viewDidLoad
{
    // Add a toolbar to the view
    CGRect toolbarFrame = CGRectMake(0, 372, 320, 44);
    UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];

    UIBarButtonItem *compassButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"compass.png"]
                                                                      style:UIBarButtonItemStyleBordered
                                                                     target:self
                                                                     action:@selector(zoomToCurrentLocation)];

    compassButton.width = 30.0f; // make the button a square shape
    [myToolbar setItems:[NSArray arrayWithObject:compassButton] animated:NO];
    [compassButton release];

    [self.view addSubview:myToolbar];
    [super viewDidLoad];
}
+3
source

. , , , - . , :  [self.navigationController setToolbarItems: control1, control2,..., nil] animated: NO];

, , , , , ( tabBar), , .

:

[self.navigationController setToolbarHidden: YES animated: YES];

- (void) viewWillDisappear: (BOOL) , NO in - (void) viewWillAppear: (BOOL) .

, .

PS: , != P

+1

-viewWillAppear:, .

0

Source: https://habr.com/ru/post/1745962/


All Articles