I'm using an mkmapview and dropping pins on to it. I would like the pins to fall one by one, rather than all simultaneously. Originally I was calling
[self performSelector:@selector(dropPin) withObject:nil afterDelay:dropTime];
where dropTime was a different delay for each pin, and dropPin was a method to make the pin drop. Unfortunately the multithreading behind this seems t开发者_运维技巧o cause a crash.
Does anyone know a better way?
If you're targeting iOS4, blocks are a great way to handle animations without worrying about delegates, callbacks, or selectors:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
if ([views count] == 0) {
return;
}
MKAnnotationView *aV;
for (aV in views) {
// set up pin beginning and end frames, shadow subview frame and center
[UIView animateWithDuration:0.75
delay:(0.0 + [views indexOfObject:aV]/10.0)
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[aV setFrame:endFrame];
// animate the shadow subview's center point
}
completion:^ (BOOL finished) {
if (finished) {
// do something here when the animation finished
}
}];
}
精彩评论