6

I have a viewController that has a tableView and a mapView, and only one is visible. I also have a toolbar with segment control with two buttons (list and map)

How do I switch between the table view and the map view ? and it's important that the toolbar will stay locked without animating with the views.

Eyal
  • 10,777
  • 18
  • 78
  • 130

3 Answers3

10

After more thinking I found a solution, add another view as a container view for both table view and map view.
This way i can do:

   [UIView transitionWithView:self.someContainerView
                     duration:1.0
                     options:UIViewAnimationOptionTransitionFlipFromLeft 
                     animations:^{
                         self.mapView.hidden   = !showingMapView;
                         self.tableView.hidden = showingMapView;
                     } completion:nil
    ];  

without flipping the toolbar

Vidhi
  • 2,026
  • 2
  • 20
  • 31
Eyal
  • 10,777
  • 18
  • 78
  • 130
4

You can use a UIView animation transition, passing the transitioning views' superview:

- (IBAction)segmentIndexChanged {
   BOOL showingMapView = (BOOL)self.segmentedControl.selectedSegmentIndex;
   [UIView transitionWithView:self.view
                     duration:1.0
                      options:UIViewAnimationOptionTransitionFlipFromLeft 
                   animations:^{
     self.mapView.hidden   = !showingMapView;
     self.tableView.hidden = showingMapView;
   } completion:nil];
}
Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
  • thanks the problem is that my toolbar is also animating, I think because he is also a subclass of the view – Eyal Apr 21 '12 at 07:53
  • @Eyal you most likely mean that it is a subview and not a subclass, correct? – Till Apr 21 '12 at 08:17
1

Try below code for show table and mapview:

Hide the mapview and tableview in segmentedControlIndexChanged:

- (IBAction)segmentedControlIndexChanged {
    switch (self.segmentedControl.selectedSegmentIndex) {
        case 0: //it's show tableview
            [UIView transitionWithView: self.view
                              duration:1.0 
                               options:UIViewAnimationOptionTransitionFlipFromLeft
                            animations:^{
                                self.mapView.hidden   = YES;
                                self.tableView.hidden = NO; }
                            completion:nil];

              break;

        case 1: //it's show mapview
            [UIView transitionWithView:self.view
                              duration:1.0
                               options:UIViewAnimationOptionTransitionFlipFromLeft
                            animations:^{
                                self.mapView.hidden   = NO;
                                self.tableView.hidden = YES; }
                            completion:nil];
            break;

        default:
              break;
    }
}
Dinesh
  • 6,500
  • 10
  • 42
  • 77
  • thanks the problem is that my toolbar is also animating, I think because he is also a subclass of the view – Eyal Apr 21 '12 at 07:55