引脚移动后MKMapView刷新

sla*_*ick 9 iphone objective-c mkpinannotationview android-mapview

使用新坐标更新自定义AnnotationView.但问题是它只能在使用MKMapView进行一些操作后进行视觉更新,例如缩放或移动.如何手动更新地图上的视觉位置?

PS.我试图将区域更改为当前地图的区域.但它确实改变了变焦.真奇怪.

[mapView setRegion:[mapView region] animated:YES];
Run Code Online (Sandbox Code Playgroud)

sla*_*ick 19

经过数小时的研究,我有点兴奋.答案是:

[mapView setCenterCoordinate:mapView.region.center animated:NO];
Run Code Online (Sandbox Code Playgroud)

不要问我为什么,但它更新了mapview,这就是我的需要.


fre*_*ace 12

MKMapView通过注意观察注释的坐标属性KVO.您只需要遵守正确的KVO协议并发送注释willChangeValueForKey:,并在更新坐标之前和之后didChangeValueForKey:使用keypath @"coordinate".

同样titlesubtitle被观察到MKMapView.所以如果你更新这些,并希望标注中值不会对您的任何努力自动改变,只是做相同的:调用willChangeValueForKey:didChangeValueForKey:


roo*_*ell 9

如果你从一个线程添加你的annoations它不会工作.我有同样的问题,只是包装我的功能,添加注释与以下工作

[self performSelectorOnMainThread:@selector(addCameraIconOnMain:) obj waitUntilDone:true];  

-(void) addCameraIconOnMain:(myobjecttype*)obj
{
    // this isnt the entire function, customize for your own purpose.....
    [mapView addAnnotation:annotation];
}
Run Code Online (Sandbox Code Playgroud)