MKAnnotationView
メソッドをサブクラス化してオーバーライドすることにより、カスタム注釈ビューを作成しようとしていますdrawRect
。MKPinAnnotationView
ピンのポイントがピンの中央ではなく、指定された座標になるように、ビューを注釈の位置からずらして描画したいと思います。そこで、以下のようにフレームの位置とサイズを設定しました。ただし、フレームの位置にはまったく影響を与えないように見えます。サイズのみです。アノテーション位置を中心に画像が描画されてしまいます。私が望むものを達成する方法に関するヒントはありますか?
MyAnnotationView.h:
@interface MyAnnotationView : MKAnnotationView {
}
MyAnnotationView.m:
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
self.canShowCallout = YES;
self.backgroundColor = [UIColor clearColor];
// Position the frame so that the bottom of it touches the annotation position
self.frame = CGRectMake(0, -16, 32, 32);
}
return self;
}
- (void)drawRect:(CGRect)rect {
[[UIImage imageNamed:@"blue-dot.png"] drawInRect:rect];
}