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];

}
4

1 回答 1

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];
 }

要获得更改,请使用委托...委托示例

于 2013-04-28T18:42:04.253 回答