Reputation: 10818
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.
Upvotes: 6
Views: 6195
Reputation: 10818
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
Upvotes: 10
Reputation: 6532
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;
}
}
Upvotes: 1
Reputation: 163228
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];
}
Upvotes: 4