当用户单击图钉时,我会显示一个自定义 UIView(就像 Zillow 应用程序一样)。现在的问题是我需要将 View 放在实际图钉的正上方。 MKAnnotationView 坐标系统与 map 相关。我怎样才能获得相对于 iPhone 屏幕的坐标,然后将我的 View 放在该坐标上。
- (void)mapView:(MKMapView *)mv didSelectAnnotationView:(MKAnnotationView *)view
{
// get view from storyboard
ZillowSearchResultAnnotation *annotation = (ZillowSearchResultAnnotation *) view.annotation;
PropertyAbstractViewController *propertyAbstractViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PropertyAbstractIdentifier"];
propertyAbstractViewController.view.frame = CGRectMake(0, 0, 100, 100);
[propertyAbstractViewController bind:annotation.data];
[mv addSubview:propertyAbstractViewController.view];
}
最佳答案
使用convertCoordinate:toPointToView: .像这样的东西:
UIView *view = ...
CGPoint p = [mv convertCoordinate:annotation.coordinate toPointToView:mv];
CGRect frame = CGRectMake(p.x,p.y,view.frame.size.width,view.frame.size.height);
view.frame = frame;
[self.view addSubView:view];
关于objective-c - 将 MKAnnotation 坐标转换为 View 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11421732/