Tengo una instancia de MKMapViewy me gustaría utilizar iconos de anotación personalizados en lugar de los iconos de pin estándar suministrados por MKPinAnnotationView. Por lo tanto, configuré una subclase de MKAnnotationView llamada CustomMapAnnotation y anulo -(void)drawRect:para dibujar una CGImage. Esto funciona.
El problema surge cuando trato de replicar la .animatesDropfuncionalidad proporcionada por MKPinAnnotationView; Me encantaría que mis íconos aparezcan gradualmente, caídos desde arriba y en orden de izquierda a derecha, cuando las anotaciones se agregan alMKMapView instancia.
Aquí está - (void) drawRect: para CustomMapAnnotation, que funciona cuando se dibuja el UIImage (que es lo que hace la 2ª línea):
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
[((Incident *)self.annotation).smallIcon drawInRect:rect];
if (newAnnotation) {
[self animateDrop];
newAnnotation = NO;
}
}
El problema surge cuando agrega el animateDropmétodo:
-(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:@];
}
Simplemente no funciona, y podría haber muchas razones por las cuales. No voy a entrar en todos ellos ahora. Lo principal que quiero saber es si el enfoque es correcto o si debería intentar algo completamente diferente.
Intenté también empaquetar todo en una transacción de animación para que el parámetro beginTime realmente funcionara; esto parecía no hacer nada en absoluto. No sé si esto se debe a que me falta algún punto clave o si es porque MapKit está destruyendo mis animaciones de alguna manera.
// Does nothing
[CATransaction begin];
[map addAnnotations:list];
[CATransaction commit];
Si alguien tiene alguna experiencia con MKMapAnnotations animadas como esta, me encantaría dar algunos consejos; de lo contrario, si puedes ofrecer consejos de CAAnimation sobre el enfoque, sería genial también.













