I would like to implement a half UITableView half MapView UIView with a button in the middle

Go To StackoverFlow.com

7

Well, this is what I want to do in my app: I would like to implment a UIView with a map on the top half of the screen and a tableview on the other half with two buttons in the middle. If I press one of the buttons the map will get fullscreen and if I press the other one the tableView will fit all the screen.

Any suggestion?

2012-04-05 17:13
by sergiocg90


7

In one view controller like a UINavigationController create an MKMapView with a frame the size of the top half of the view and add it as subview of your view controller. Then I would create a UIToolbar to hold your buttons and make the top of it's frame line up with bottom of the MKMapView. Finally create a UITableView with it's frame just below the others (make sure you hook up it's delegates).

Then assign the target of your UIBarButtonItem that makes the map go fullscreen to a method that animates the frames of all three views like this:

[UIView animateWithDuration:0.24 
                      delay:0.0
                    options:UIViewAnimationCurveEaseOut
                 animations:(void (^)(void)) ^{
                     self.toolbar.frame = CGRectMake(0, MAP_HEIGHT_FULLSCREEN, 320, TOOLBAR_HEIGHT);
                     self.mapView.frame = CGRectMake(0,0,320,MAP_HEIGHT_FULLSCREEN);
                     self.tableView.frame = CGRectMake(0, MAP_HEIGHT_FULLSCREEN+TOOLBAR_HEIGHT, 320, MAP_HEIGHT_FULLSCREEN-MAP_HEIGHT);
                 }
                 completion:^ (BOOL finished){}
 ];
2012-04-05 17:29
by Steve Moser
Wow thank you! I have already implemented it and looks really great - sergiocg90 2012-04-05 18:43
@SergioCalvoGonzález You're welcome. If my answered helped you don't forget to up vote - Steve Moser 2012-04-05 21:18
sorry, but I can not up vote yet.. - sergiocg90 2012-04-06 07:53


1

Create both views how you are planning, On one button click, change the frame of one view to fit the full screen, if you click the other button, do the same thing to the other view.

2012-04-05 17:15
by PRNDL Development Studios
Do you mean creating two viewcontrollers? Or in the same viewController implement both and change the frame when a button is pressed - sergiocg90 2012-04-05 17:18
1 viewcontroller. 2 views. Change the frames of the views - PRNDL Development Studios 2012-04-05 17:24
Ads