2014-05-09 63 views
1

我有选择MKAnnotationView后自定义视图,并与我尝试添加一个手势识别这样的:自定义标注手势识别

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)selectedAnnotationView { 
    if([selectedAnnotationView.annotation isKindOfClass:[CustomPinAnnotation class]]) { 
     CustomPinAnnotation *annotation = selectedAnnotationView.annotation; 
     [selectedAnnotationView setCalloutOffset:CGPointMake(0,selectedAnnotationView.frame.size.height)]; 

     CalloutView *calloutView = [[CalloutView alloc] initWithFrame:CGRectMake(0, 0, selectedAnnotationView.frame.size.width, selectedAnnotationView.frame.size.height*2)]; 

    [selectedAnnotationView addSubview:calloutView]; 
    [UIView animateWithDuration:annotationAnimationTime animations:^{ 
     [calloutView setFrame:CGRectMake(-expandingAnnotationWidth/8, 0, [calloutView calculateWurstLenghtFromText:selectedAnnotationView.annotation.title], selectedAnnotationView.frame.size.height*2)]; 
    } completion:^(BOOL finished) { 
     UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(calloutTapped:)]; 
     [calloutView addGestureRecognizer:tapGesture]; 
     [calloutView setUserInteractionEnabled:YES]; 
    }]; 
} 

在屏幕下方,你可以看到它的样子扩大,而不是: enter image description here

的问题是,手势识别仅适用于显着的区域,而不是对整个标注:

enter image description here

我可能知道发生了什么 - 我添加子视图到MKAnnotation这是很小的。但如何解决这个问题?还有另一种绘制标注的方法,或者我可以扩展可点击区域。

回答

0

您的注释框架可能太小。即使您将标注设置得足够大,其父标注本身也很小。有同样的问题,它解决它真的很混乱。

如果你不想惹框架和选择的状态,也因为你已经在使用被添加自定义视图,你为什么不执行以下操作:

  • 添加自定义标注鉴于作为一个完全新的/不同的注释/覆盖时注释被选中(而不是像现在这样子视图)
  • 删除它当你的注释取消

你只需要正确定位并不会甚至需要一个手势识别器。

1

1Maybe你可以尝试改变这一点:

CalloutView *calloutView = [[CalloutView alloc] initWithFrame:CGRectMake(0, 0, selectedAnnotationView.frame.size.width, selectedAnnotationView.frame.size.height*2)]; 

要这样:

CalloutView *calloutView = [[CalloutView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)]; 

,看看它是否工作,因为我有一种感觉,annotationView.frame太小,并设置您的calloutView只是为了这个小区域。如果它是硬编码的,它可能会起作用。

+0

但框架是正确的 - 我看到正确绘图。除了这个框架被改变与下面提到的动画几行。 – Kuba

+0

只需登录您的calloutView.frame并检查其值。我可能是错的,但之前我有过类似的问题,这是造成它的原因。我会看看可能的代码,看看我如何设法处理这个tapGesture – Pancho

+0

我记录它:'frame =(-25 0; 270 120);'在动画之后。是正确的大小。 – Kuba