我对这些答案都没有太多的运气。做我自己的捏只是冲突太多。我遇到的情况是,普通的缩放比我自己捏的时候缩小得更远。
本来,我想为楼主做这样的事情:
- (void) mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
MKCoordinateRegion region = mapView.region;
//...
// adjust the region.center
//...
mapView.region = region;
}
我发现他就是那个没有任何影响。我还通过NSLog
发现,即使我以编程方式设置region
或centerCoordinate
,该方法也会启动。这导致了这样一个问题:“如果DID工作无法完成,上面不会有这样的问题吗?“
所以我揣测和假设到现在,虽然用户缩放/滚动/旋转正在发生的MapView某种程度上抑制或忽略更改区域。关于仲裁的东西呈现纲领性调整无能为力。
如果是这样的那么问题的关键是如何让区域调整在regionDidChanged:
通知之外,并且由于任何调整都会触发另一个通知,因此重要的是它能够确定何时不再调整,这导致我进行了以下实现(其中subject
提供了我想停留在中间的中心坐标):
- (void) recenterMap {
double latDiff = self.subject.coordinate.latitude self.mapView.centerCoordinate.latitude;
double lonDiff = self.subject.coordinate.longitude - self.mapView.centerCoordinate.longitude;
BOOL latIsDiff = ABS(latDiff) > 0.00001;
BOOL lonIsDiff = ABS(lonDiff) > 0.00001;
if (self.subject.isLocated && (lonIsDiff || latIsDiff)) {
[self.mapView setCenterCoordinate: self.subject.coordinate animated: YES];
}
}
- (void) mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
if (self.isShowingMap) {
if (self.isInEdit) {
self.setLocationButton.hidden = NO;
self.mapEditPrompt.hidden = YES;
}
else {
if (self.subject.isLocated) { // dispatch outside so it will happen after the map view user events are done
dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^{
[self recenterMap];
});
}
}
}
}
将其滑回的延迟时间可能会有所不同,但它确实工作得很好。并让地图互动在发生时保持Apple式。
我收到这样做,但没有处理它的方式不同。我禁用了与MKMapView的交互,并在其上方添加了捏手势识别器。然后,我将捏合手势转换为相应的缩放级别。所以几乎在功能上自己捏合缩放。由于这不能直接回答你的问题,如果这对你来说是一个可行的选择,我会在代码中回答问题。 – random 2012-08-14 05:38:06