停止MKMapView的惯性滚动

时间:2013-07-02 08:15:38

标签: ios objective-c scroll mkmapview

问题在于:我的MKMapViewscrollEnabled=YESzoomEnabled=YES,我有一个按钮,可以将某些区域设置为地图并设置scrollEnabled=NO和{ {1}}。

当我点击该按钮时,一切正常。但是,如果我滚动我的地图,所以它开始进一步滚动'惯性原因并点击我的按钮,而地图继续滚动我陷入惯性滚动期间我的地图滚动到的区域。

如果有帮助的话,这里有一些代码:

zoomEnabled=NO

所以我想要的是当我按下按钮时能够立即停止MKMapView的惯性滚动。

1 个答案:

答案 0 :(得分: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);
}
相关问题