現在、CGAffineTransformMakeRotation を使用して MKAnnotationView の画像プロパティを回転させています。ただし、この場合、吹き出しの吹き出しだけでなく、ビュー全体が回転します。そのため、 MKAnnotationView Only Rotate the Image プロパティ内の提案に従い、現在 UIImageView を作成し、それをサブビューとして MKAnnotationView に追加しています。画像が表示され、問題なく回転するようになりました。ただし、現在 MKAnnotationView はタッチ イベントに応答しません。以前と同じように動作する必要があります-タップ/タッチすると、吹き出しの吹き出しが表示されるはずです。私がしなければならないことはありますか?
私が試した最初の方法(コールアウトバブルを回転させる):
MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
aView.image = [UIImage imageNamed:@"mapPin.png"];
float newRad = degreesToRadians(degreesToRotate);
[aView setTransform:CGAffineTransformRotate(CGAffineTransformIdentity, newRad)];
UIImageView を使用してサブビューとして追加する:
MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
UIImageView *iv = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mapPin.png"]];
iv.userInteractionEnabled = YES;
[aView addSubview:iv];
aView.canShowCallout = YES;
更新 ジェスチャ認識機能を追加しようとしましたが、機能しません。マップ上の MKAnnotationView 内の UIImageView をタップすると、imageTapped メソッドが呼び出されません。これはメソッド内にあります: - (MKAnnotationView *)mapView:(MKMapView *)mView viewForAnnotation:(id )annotation
MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
UIImageView *iv = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mapPin.png"]];
iv.userInteractionEnabled = YES;
iv.exclusiveTouch = NO;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
[iv addGestureRecognizer:tapGesture];
[aView addSubview:iv];