Custom pin animation - MKMapView

前端 未结 5 523
生来不讨喜
生来不讨喜 2020-12-08 08:54

I have used pin images in application instead of standard pin, now i want to give animation (dropping effect as it was with standard pins) to custom pins. How can i provide

5条回答
  •  醉酒成梦
    2020-12-08 09:11

    It feels also a lot cooler if you do not drop all the pins at once but drop each of them with a small delay so that it will look like there is a rain of pins effect. Similar to what Apple does natively. Use this:

    - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 
        MKAnnotationView *aV; 
    
        float delay = 0.00;
    
        for (aV in views) {
            CGRect endFrame = aV.frame;
    
            aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - 430.0, aV.frame.size.width, aV.frame.size.height);
            delay = delay + 0.01;
    
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDelay:delay];
            [UIView setAnimationDuration:0.45];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            [aV setFrame:endFrame];
            [UIView commitAnimations];
        }
    }
    

提交回复
热议问题