4

Here is the problem: I have my MKMapView with scrollEnabled=YES and zoomEnabled=YES, I have a button that sets some certain region to the map and sets scrollEnabled=NO and zoomEnabled=NO.

Everything works fine when I simply tap that button. But if I scroll my map a bit so it starts to scroll further 'cause of inertia and tap my button while map continues to scroll I get stuck in the region my map scrolled to during inertia scrolling.

Here's some code if it helps:

- (void)openMap
{
    MKMapView * mapView = self.contentView.locationView.mapView;
    mapView.scrollEnabled = YES;
    mapView.zoomEnabled = YES;
}

- (void)closeMap
{
    MKMapView * mapView = self.contentView.locationView.mapView;
    mapView.scrollEnabled = NO;
    mapView.zoomEnabled = NO;
    CLLocationCoordinate2D coord = {self.event.eventLocation.latitude.floatValue, self.event.eventLocation.longitude.floatValue};
    mapView.region = MKCoordinateRegionMakeWithDistance(coord, 500, 500);
}

So what I want is to be able to instantly stop that inertia scroll of MKMapView when I press my button.

4

1 回答 1

0

这似乎是 MKMapView 实现中的一个错误。我唯一的解决方案是在 closeMap 方法中重新创建地图。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[self addMap];
}

- (void)addMap {

self.map = [[MKMapView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:self.map];
[self.view sendSubviewToBack:self.map];
}


- (void)recreateMap {

[self.map removeFromSuperview];
self.map = nil;
[self addMap];
}


- (void)openMap
{
MKMapView * mapView = self.map;
mapView.scrollEnabled = YES;
mapView.zoomEnabled = YES;
}


- (void)closeMap {

[self recreateMap];
MKMapView * mapView = self.map;
mapView.scrollEnabled = NO;
mapView.zoomEnabled = NO;
CLLocationCoordinate2D coord = {self.event.eventLocation.latitude.floatValue, self.event.eventLocation.longitude.floatValue};
mapView.region = MKCoordinateRegionMakeWithDistance(coord, 500, 500);
}
于 2013-07-02T14:38:06.587 回答