Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MKAnnotationView子视图上的UITapGestureRecognitor不工作_Ios_Objective C_Mkannotationview_Uitapgesturerecognizer - Fatal编程技术网

Ios MKAnnotationView子视图上的UITapGestureRecognitor不工作

Ios MKAnnotationView子视图上的UITapGestureRecognitor不工作,ios,objective-c,mkannotationview,uitapgesturerecognizer,Ios,Objective C,Mkannotationview,Uitapgesturerecognizer,我正在尝试添加点击识别器以显示其他信息标注。我试着直接调用选择器“showPersonInfo”,结果它成功了。但是,当我尝试将其添加到我正在处理的MKAnnotationView子视图的UITapGestureRecognitor中时。当我点击时,选择器没有启动 此代码位于MKAnnotationView子类的.m内部 - (void)layoutSubviews { [self addSubView:self.imageContainerView]; UITapGestu

我正在尝试添加点击识别器以显示其他信息标注。我试着直接调用选择器“showPersonInfo”,结果它成功了。但是,当我尝试将其添加到我正在处理的MKAnnotationView子视图的UITapGestureRecognitor中时。当我点击时,选择器没有启动

此代码位于MKAnnotationView子类的.m内部

- (void)layoutSubviews {

    [self addSubView:self.imageContainerView];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPersonInfo:)];
    [self.imageContainerView addGestureRecognizer:tap];

}

- (void)showPersonInfo:(UITapGestureRecognizer *)tap {

    NSLog(@"annotation imageView touched");
    [self addSubview:self.personInfoView];

}

可以使用mapView委托方法向注释视图添加操作

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
    {
        if (annotation == mapView.userLocation)
            return nil;

        static NSString *s = @"identifier";
        MKAnnotationView *pin = [mapView dequeueReusableAnnotationViewWithIdentifier:s];
        if (!pin) {
            pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:s];
            pin.canShowCallout = YES;
            pin.image = [UIImage imageNamed:@"pin.png"];
            pin.calloutOffset = CGPointMake(0, 0);
            UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            [button addTarget:self
                       action:@selector(showPersonInfo:) forControlEvents:UIControlEventTouchUpInside];
            pin.rightCalloutAccessoryView = button;
        }
        return pin;
    }
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
if(注释==mapView.userLocation)
返回零;
静态NSString*s=@“标识符”;
MKAnnotationView*引脚=[mapView dequeueReusableAnnotationViewWithIdentifier:s];
如果(!pin){
pin=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:s];
pin.canShowCallout=是;
pin.image=[UIImage ImageName:@“pin.png”];
pin.calloutOffset=CGPointMake(0,0);
UIButton*button=[UIButton button类型:UIButtonTypedTailButton];
[按钮添加目标:自我
操作:@选择器(showPersonInfo:)用于控制事件:UIControlEventTouchUpInside];
pin.rightCalloutAccessoryView=按钮;
}
回位销;
}

您需要注意的两件事:

默认情况下,
UIIMageView.userInteraction
被禁用

   self.imageContainerView.userinteractionenabled = yes;
UITAPPORATE:

[tapRecognizer setDelegate:self];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setNumberOfTouchesRequired:1];

self.imageContainerView只是一个包含多个UIImageView的UIView。这会影响识别器吗?不,请正确检查UITapPicture。我已在批注中添加了标题,但即使-(void)mapView:(MKMapView*)mapView未选择AnnotationView:(MKAnnotationView*)视图仍不会启动。这是为我调用的。检查MKMapViewDelegate是否设置正确。我现在知道问题所在。我没有将MKAnnotationView的图像设置为命中区域,至少在我的案例中是这样。然后使用上面提供的按钮执行选择器。谢谢@Suhail k。现在调用显示出来了。酷。我不明白确切的问题是什么?