2010-11-24 67 views
3

正如您在下面看到的,我有一个注释视图,它有一个右键。当用户点击右键时,我正在呈现弹出窗口 - 问题是我不知道用户点击的位置,因此我没有X和Y来相应地显示弹出窗口。如何跟踪右侧标注附件视图的位置

如何找出用户点击哪里,即X和Y?

HotelAnnotationView *customPinView = [[HotelAnnotationView alloc] initWithAnnotation:theHotel reuseIdentifier:hotelPin]; 

//The right button which allows user to see hotel information 
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[rightButton addTarget:self action:@selector(showDetailsForHotel:) forControlEvents:UIControlEventTouchUpInside]; 

rightButton.tag = theHotel.id; 
customPinView.rightCalloutAccessoryView = rightButton; 

回答

6

简单地实现

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 

这将让叫上您的代理每次用户点击的calloutAccessoryControl。然后,您可以通过

view.annotation 

我喜欢这种方法比使用(ID)更好的原因访问你注释属性发件人是,你实际上可以访问不仅是你的注释纬度&长坐标,但这是任何数据实际上与它相关联,所以你可以在弹出视图中使用它。

1

动作方法showDetailsForHotel:包括sender参数,它是已被窃听的按钮。你可以问任何视图的坐标。