当用户单击图钉时(例如Zillow应用),我正在显示自定义UIView。现在的问题是,我需要将视图放置在实际引脚上方。 MKAnnotationView坐标系与地图有关。如何获取相对于iPhone屏幕的坐标,然后将视图放在该坐标上。
- (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];