正如您在下面看到的,我有一个带有右键的注释视图。当用户点击右侧按钮时,我将呈现一个弹出窗口 - 问题是我不知道用户点击的位置,因此我没有 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;
只需实施
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
每当用户点击标注附件控制时,您的代理就会调用它。然后您可以通过以下方式访问注释属性
view.annotation
与使用 (id)sender 相比,我更喜欢这种方法的原因是,您实际上不仅可以访问注释纬度和经度坐标,还可以访问与其实际关联的任何数据,以便您可以在弹出视图中使用它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)