1

ユーザーが複数のオーバーレイ (すべて同じ種類) を持つマップ上の MKCircleView オーバーレイをクリックできるアプリを作成しようとしています。ユーザーがクリックしたオーバーレイに応じて、特定のメッセージが表示されます。

私の最初のアプローチは、mapView:viewForOverlay: によって提供される mapView に UITapGestureRecognizer を追加することでしたが、うまくいきませんでした。

次に、MKCircleView をサブクラス化し、次のメソッドを実装しました。

//subclassed to handle event when touches are received
- (void) actionWhenClicked {
    UIAlertView *a =[[UIAlertView alloc] initWithTitle:@"It worked!"
                                               message:@"yeah"
                                              delegate:nil
                                     cancelButtonTitle:@"OK"
                                     otherButtonTitles: nil];
    [a show];
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [self actionWhenClicked];

}

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesCancelled:touches withEvent:event];
    [self actionWhenClicked];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    [self actionWhenClicked];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesMoved:touches withEvent:event];
    [self actionWhenClicked];

}

マップ上の各オーバーレイは上記のサブクラスのインスタンスであるため、タッチすると応答する必要があります。ただし、メソッドが呼び出されることはありません。私はそれが働いていたUIViewで同じアプローチを試みました。ただし、オーバーレイのあるマップでは機能しません。

何か案は?

4

0 に答える 0