のインスタンスがMKMapView
あり、MKPinAnnotationView によって提供される標準のピン アイコンの代わりにカスタムの注釈アイコンを使用したいと考えています。そのため、CustomMapAnnotation と呼ばれる MKAnnotationView のサブクラスをセットアップし、CGImage-(void)drawRect:
を描画するためにオーバーライドしています。これは機能します。
.animatesDrop
MKPinAnnotationView によって提供される機能を複製しようとすると、問題が発生します。注釈がMKMapView
インスタンスに追加されると、アイコンが上から左から右の順にドロップされて徐々に表示されることを望みます。
ここに -(void)drawRect: があります: CustomMapAnnotation の場合、UIImage を描画するだけで機能します (これは 2 行目です)。
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
[((Incident *)self.annotation).smallIcon drawInRect:rect];
if (newAnnotation) {
[self animateDrop];
newAnnotation = NO;
}
}
animateDrop
メソッドを追加すると問題が発生します。
-(void)animateDrop {
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGPoint finalPos = self.center;
CGPoint startPos = CGPointMake(self.center.x, self.center.y-480.0);
self.layer.position = startPos;
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"position"];
theAnimation.fromValue=[NSValue valueWithCGPoint:startPos];
theAnimation.toValue=[NSValue valueWithCGPoint:finalPos];
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;
theAnimation.delegate = self;
theAnimation.beginTime = 5.0 * (self.center.x/320.0);
theAnimation.duration = 1.0;
[self.layer addAnimation:theAnimation forKey:@""];
}
うまくいかないだけで、多くの理由が考えられます。今はそれらすべてには立ち入りません。私が知りたい主なことは、アプローチがまったく正しいかどうか、またはまったく別のことを試す必要があるかどうかです。
また、beginTime パラメーターが実際に機能するように、すべてをアニメーション トランザクションにパッケージ化しようとしました。これはまったく何もしていないように見えました。これは、重要なポイントが欠けているためなのか、それとも MapKit が何らかの方法でアニメーションを台無しにしているからなのかはわかりません。
// Does nothing
[CATransaction begin];
[map addAnnotations:list];
[CATransaction commit];
このようなアニメーション化された MKMapAnnotations を使用した経験がある場合は、いくつかのヒントが欲しいです。それ以外の場合は、アプローチに関する CAAnimation のアドバイスを提供できれば、それも素晴らしいことです。