我有选择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];
}];
}
在屏幕下方,你可以看到它的样子扩大,而不是:
的问题是,手势识别仅适用于显着的区域,而不是对整个标注:
我可能知道发生了什么 - 我添加子视图到MKAnnotation
这是很小的。但如何解决这个问题?还有另一种绘制标注的方法,或者我可以扩展可点击区域。
但框架是正确的 - 我看到正确绘图。除了这个框架被改变与下面提到的动画几行。 – Kuba
只需登录您的calloutView.frame并检查其值。我可能是错的,但之前我有过类似的问题,这是造成它的原因。我会看看可能的代码,看看我如何设法处理这个tapGesture – Pancho
我记录它:'frame =(-25 0; 270 120);'在动画之后。是正确的大小。 – Kuba