我有一个自定义的calloutview,当用户点击MKannotationView时调用它
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
// NSInteger indexOfTheObject = [self.mapView.annotations indexOfObject:view.annotation];
if([view.annotation isKindOfClass:[Estabelecimento class]])
{
CalloutView *calloutView = [[CalloutView alloc]initWithFrame:CGRectMake(0, 0, 230, 100)];
[calloutView setDelegate:self];
CGRect calloutViewFrame = calloutView.frame;
calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height);
calloutView.frame = calloutViewFrame;
[calloutView.calloutTitleLabel setText:[(Estabelecimento*)[view annotation] title]];
[calloutView.calloutEndLabel setText:[(Estabelecimento *)[view annotation] subtitle]];
[view addSubview:calloutView];
}
}
但是,我无法跟踪用户何时在该视图中点击。此代码位于自定义calloutview
中UIButton * interactionButton = [UIButton buttonWithType:UIButtonTypeCustom];
[interactionButton setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[interactionButton addTarget:self action:@selector(clickedInside:) forControlEvents:UIControlEventTouchUpInside];
[interactionButton setBackgroundColor:[UIColor clearColor]];
[self addSubview:interactionButton];
[self setUserInteractionEnabled:YES];
-(void)clickedInside:(id)tap
{
NSLog(@"clicked inside");
}
永远不会调用该方法,已尝试在该视图中执行UITapGestureRecognizer
,并且也不起作用。
可以跟踪用户交互吗?