Joh*_*rck 2 mapkit mkmapview ios
如何将mapView集中在MKAnnotationView的calloutAccessory上?我知道如何将地图置于实际的annotationView中心,但我不知道如何将地图置于annotationView的calloutAccessory中心.有任何想法吗?
// This centers the map on the MKAnnotationView. However, I need to be able to
// center the map on the MKAnnotationView's calloutAccessory.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
id<MKAnnotation> annotation = view.annotation;
[self.mapView setCenterCoordinate:[annotation coordinate] animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
您可以使用MKMapView方法convertPoint: toCoordinateFromView:方法将注释视图的中心转换为坐标,然后将地图置于该坐标的中心 -
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
CGPoint annotationCenter=CGPointMake(control.frame.origin.x+(control.frame.size.width/2),control.frame.origin.y+(control.frame.size.height/2));
CLLocationCoordinate2D newCenter=[mapView convertPoint:annotationCenter toCoordinateFromView:control.superview];
[mapView setCenterCoordinate:newCenter animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1558 次 |
| 最近记录: |