2013-04-28 106 views
1

我希望用户能够通过像苹果地图或地图上的按钮一样卷曲右角来更改地图上的地图类型。有任何想法吗?允许用户更改地图类型

- (void)setUpMap { 
//setMap 

MKMapView *mapView = [[MKMapView alloc] initWithFrame:CGRectMake(10, 14, (self.bounds.size.width - (10 * 2)), (self.bounds.size.height - (10 * 2)))]; 

mapView.layer.borderColor = kITBarTint.CGColor; 
mapView.layer.borderWidth = 1.0; 
mapView.layer.cornerRadius = 15.0; 
mapView.layer.shadowColor = [UIColor blackColor].CGColor; 
mapView.layer.shadowOffset = CGSizeMake(5, 5); 
mapView.layer.shadowRadius = 10; 
mapView.mapType = MKMapTypeHybrid; 

[mapView setDelegate:self]; 
[mapView setShowsUserLocation:NO]; 

[self addSubview:mapView]; 


NSMutableArray *locations = [NSMutableArray array]; 
BOOL isFirst = YES; 
for (ITLocation *location in self.spider.locations) { 
    ITObjectMark *mark = [[ITObjectMark alloc] initWithCoordinate:[location geopoint] addressDictionary:nil]; 
    mark.Object = self.Object; 
    [locations addObject:mark]; 
    if (isFirst) { 

     int zoomLevel = 2; 

     // use the zoom level to compute the region 
     [mapView setCenterCoordinate:[location geopoint] zoomLevel:zoomLevel animated:YES]; 
     isFirst = NO; 
    } 
} 

[mapView addAnnotations:locations]; 

} 

回答

5

您可以使用UISegmentedControler来设置地图类型。但对于卷曲你需要你的地方你的按钮,并与presentmodalviewcontroller风格模式的过渡部分卷曲呈现它的一个新的视图控制器...

- (IBAction)setMap:(id)sender { 

    switch (((UISegmentedControl *)sender).selectedSegmentIndex) { 

     case 0: 
     { 
      mapView.mapType = MKMapTypeStandard; 
      break; 
     } 

     case 1: 
     { 
      mapView.mapType = MKMapTypeSatellite; 
      break; 
     } 

     case 2: 
     { 
      mapView.mapType = MKMapTypeHybrid; 
      break; 
     } 
    } 
} 

但卷曲你,你把你的按钮,并提出需要一个新的视图控制器它presentmodalviewcontroller风格模式的过渡部分卷曲... //例

- (IBAction)goToSecond:(id)sender 
{ 
    InfoController *ainfoController = [[InfoController alloc] 
             initWithNibName:@"InfoController" bundle:nil]; 
    ainfoController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
    [self presentModalViewController:ainfoController animated:YES]; 
} 

要得到改变使用委托... Delegate example

+0

非常感谢你,一套好的溶胶utions – Steve 2013-04-28 19:09:22