将MKAnnotation坐标转换为视图坐标 [英] Convert MKAnnotation Coordinates to View Coordinates
问题描述
当用户点击图钉时,我正在显示自定义UIView(如Zillow应用程序)。现在问题是我需要将视图放在实际引脚的正上方。 MKAnnotationView坐标系与地图相关。如何获取相对于iPhone屏幕的坐标,然后将我的视图放在该坐标上。
I am displaying a custom UIView when the user clicks on the pin (Like the Zillow app). Now the problem is that I need to place the view right above the actual pin. The MKAnnotationView coordinates system is related to the map. How can I get the coordinates with respect to the iPhone screen and then place my view on that coordinate.
- (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];
}
推荐答案
使用< a href =http://developer.apple.com/library/ios/DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/occ/instm/MKMapView/convertCoordinate%3atoPointToView%3a> 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];
这篇关于将MKAnnotation坐标转换为视图坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!