我有我在哪里执行以下操作注释的地图:检查是否用户已经选择了另一个注释在地图
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view{
[self methodA];}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
[self methodB];}
两种方法A和B删除或mapView.superview添加视图。
当处理一个注释时,所有的工作都很好。 问题是当我有多个注释,并且我选择了两个,一个接一个的时候,另一个是。
如果我点击地图中的任何其他地方,一切正常。但是当我在第一个注释视图之后点击第二个注释视图时,它执行“didDeselectAnnotationView”,然后是“didSelectAnnotationView”,它同时调用方法A和B,但这不是我想要的。我希望它能检测到我点击了另一个注释并忽略了这两种方法。
我已经研究过这个,但还没有找到任何解决方案。
我尝试添加一个全局变量并使用它,以及识别用户触摸:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
// Get the specific point that was touched
CGPoint point = [touch locationInView:self.mapView];
for (id<MKAnnotation> annotation in self.mapView.annotations) {
MKAnnotationView* anView = [self.mapView viewForAnnotation: annotation];
if (anView){
CGRect frame = CGRectMake(anView.frame.origin.x-5, anView.frame.origin.y-5, anView.frame.size.width+5, anView.frame.size.height+5);
if (CGRectContainsPoint(frame, point)) {
NSLog(@"BELONGS");
}
}
}}
然而,这并没有捕捉到所有的接触,再加上它是一个有点意大利面条解决方案。
任何想法如何解决这个问题?
所有最优秀的
可能类似:http://stackoverflow.com/questions/23667606/detect-when-a-second-annotation-is-selected-in- a-mkmapview – Anna 2014-12-02 11:41:24
接受的答案使用[self performSelector:@selector(checkShouldHideBottomView :) withObject:view afterDelay:0.5]; 我认为这不适合做。 – jonypz 2014-12-02 19:58:36