1

大きな問題があります。サブクラス化して、それぞれ 3 つを画像付きMKAnnotationViewで追加しましUIImageViewsた。注釈は地図上できれいに見えます。ただし、タッチ イベントはキャプチャされません。私はすべてを試しましself.userInteractionEnabledexclusiveTouchが、何もうまくいかないようです。

  • (id)initWithAnnotation:(id)annotation reuseIdentifier:(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

MKMapViewDelegate を使用mapView:didSelectAnnotationView:して、注釈自体のタップを操作しようとするのではなく、ユーザーが注釈をタップしたことを検出します。

どのアノテーションが選択されたかを把握し、 から適切なアクションを実行できmapView:didSelect...ます。

于 2012-09-21T01:09:31.547 に答える