如何跟踪点击时正确的标注附件视图在何处 [英] How to track where the right callout accessory view is when it was tapped on

查看:38
本文介绍了如何跟踪点击时正确的标注附件视图在何处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您在下面看到的,我有一个带有右键的注释视图.当用户点击右按钮时,我将显示一个弹出框-问题是我不知道用户在哪里轻按,因此我没有X和Y来显示相应的弹出框.

As you can see below I have an annotation view that has a right button. When the user taps the right button I am presenting a popover - the problem is I don't know where the user tapped so I don't have the X and Y to display the popover accordingly.

我如何找出用户点击的位置,即X和Y?

How do I find out where the user tapped i.e. the X and 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;

推荐答案

简单实施

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

每当用户单击calloutAccessoryControl时,将在您的代理上呼叫该呼叫.然后,您可以通过

Which will get called on your delegate everytime a user taps the calloutAccessoryControl. You can then access you annotation properties through

view.annotation

与使用(id)sender相比,我更喜欢这种方法的原因是,您实际上不仅可以访问注释lat&长坐标,但实际上有任何与其相关的数据,因此您可以在弹出视图中使用它.

The reason I like this approach better than using the (id)sender is that you actually get access to not only your annotation lat & long coordinates, but any data that is actually associated with it so you can use that in your pop over view.

这篇关于如何跟踪点击时正确的标注附件视图在何处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆