1

我有一个大问题。我已经分类MKAnnotationView并添加了三个UIImageViews,每个都带有一个图像。注释在地图上看起来很好。但是,它们不捕获触摸事件。我已经尝试了所有方法self.userInteractionEnabledexclusiveTouch但似乎没有任何效果。

  • (id)initWithAnnotation:(id)注解重用标识符:(NSString *)reuseIdentifier {

    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    self.frame = CGRectMake(0, 0, kWidth, kHeight);
    
    
    UIImage *image = [UIImage imageNamed:@"geo-icon.png"];
    
    UIImageView * turbineView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(0.0, 0.0, image.size.width, image.size.height) ];
    
    UIImageView * mastroView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(20.0, 100.0, image.size.width, image.size.height) ];
    mastroView.image = image;
    mastroView.userInteractionEnabled = NO;
    mastroView.exclusiveTouch = NO;
    
    
    [turbineView addSubview:mastroView];
    
    image = [UIImage imageNamed:@"turbine-noshadow.png"];
    propellerView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(4.0, 82.0, image.size.width, image.size.height) ];
    propellerView.image = image;
    propellerView.userInteractionEnabled = NO;
    propellerView.exclusiveTouch = NO;
    [turbineView addSubview:propellerView];
    
    image = [UIImage imageNamed:@"arrow.png"];
    UIImageView * arrowView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(32.0, 114.0, image.size.width, image.size.height) ];
    arrowView.image = image;
    arrowView.userInteractionEnabled = NO;
    arrowView.exclusiveTouch = NO;
    [turbineView addSubview:arrowView];
    
    image = [UIImage imageNamed:@"run-turbine.png"];
    UIImageView * stoprunView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(65.0, 155.0, image.size.width, image.size.height) ];
    stoprunView.image = image;
    stoprunView.userInteractionEnabled = NO;
    stoprunView.exclusiveTouch = NO;
    [turbineView addSubview:stoprunView];
    turbineView.userInteractionEnabled = NO;
    turbineView.exclusiveTouch = NO;
    
    
    
    
    [self addSubview:turbineView];
    self.userInteractionEnabled = NO;
    self.exclusiveTouch = NO;
    self.opaque = NO;
    
    [self rodar];  //
    return self;
    

}

4

1 回答 1

0

使用 MKMapViewDelegatemapView:didSelectAnnotationView:来检测用户何时点击注释,而不是尝试与注释本身的点击进行交互。

您可以确定选择了哪些注释并从中采取适当的操作mapView:didSelect...

于 2012-09-21T01:09:31.547 回答