2010-04-16 19 views
9

मैंने मानक पिन की बजाय एप्लिकेशन में पिन छवियों का उपयोग किया है, अब मैं कस्टम पिन पर एनीमेशन (मानक पिन के साथ प्रभाव डालना) देना चाहता हूं। मैं कस्टम पिन छवियों को छोड़ने एनीमेशन प्रभाव कैसे प्रदान कर सकते हैं ????कस्टम पिन एनीमेशन - एमकेमैप व्यू

+0

[यह मदद करनी चाहिए] (http://stackoverflow.com/questions/1857160/how-can-i-create-a-custom-pin-drop- एनीमेशन-उपयोग-mkannotationview) – dwery

उत्तर

24

निम्नलिखित प्रतिनिधि विधि लागू करें।

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 
    MKAnnotationView *aV; 
    for (aV in views) { 
    CGRect endFrame = aV.frame; 

    aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - 230.0, aV.frame.size.width, aV.frame.size.height); 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.45]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
     [aV setFrame:endFrame]; 
    [UIView commitAnimations]; 

    } 
} 
+5

यह बहुत अच्छा काम किया। सही जवाब चिह्नित किया जाना चाहिए। –

6

यह यदि आप एक साथ सभी पिन ड्रॉप नहीं है, लेकिन एक छोटी सी देरी के साथ उनमें से प्रत्येक ड्रॉप इतना है कि यह दिखेगा पिन प्रभाव की बारिश होती है की तरह यह भी एक बहुत कूलर महसूस करता है। ऐप्पल ने मूल रूप से क्या किया है। इसका उपयोग करें:

- (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]; 
    } 
} 
+0

हाँ यह अच्छा है! धन्यवाद – PrasadW

0

यह मेरे लिए अच्छा काम करता है। नहीं कर सकते याद जहां मैं इस पर यहां पाया हालांकि

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 
MKAnnotationView *aV; 

for (aV in views) { 

    // Don't pin drop if annotation is user location 
    if ([aV.annotation isKindOfClass:[MKUserLocation class]]) { 
     continue; 
    } 

    // Check if current annotation is inside visible map rect, else go to next one 
    MKMapPoint point = MKMapPointForCoordinate(aV.annotation.coordinate); 
    if (!MKMapRectContainsPoint(self.mapView.visibleMapRect, point)) { 
     continue; 
    } 

    CGRect endFrame = aV.frame; 

    // Move annotation out of view 
    aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height, aV.frame.size.width, aV.frame.size.height); 

    // Animate drop 
    [UIView animateWithDuration:0.3 delay:0.03*[views indexOfObject:aV] options:UIViewAnimationCurveLinear animations:^{ 

     aV.frame = endFrame; 

     // Animate squash 
    }completion:^(BOOL finished){ 
     if (finished) { 
      [UIView animateWithDuration:0.05 animations:^{ 
       aV.transform = CGAffineTransformMakeScale(1.0, 0.8); 

      }completion:^(BOOL finished){ 
       if (finished) { 
        [UIView animateWithDuration:0.5 animations:^{ 
         aV.transform = CGAffineTransformIdentity; 
        }]; 
       } 
      }]; 
     } 
    }]; 
    } 
} 
0

ध्यान दें कि एनोटेशन दृश्य एनिमेट -mapView:didAddAnnotationViews: में अजीब प्रभाव का कारण बनता है जब MKMapView.userTrackingModeMKUserTrackingModeFollowWithHeading बराबर होती है। मेरी इच्छा है कि ऐप्पल ने MKAnnotationView कक्षा में ड्रॉप ड्रॉप एनीमेशन उपलब्ध कराया है।

0

स्विफ्ट 3 ड्रॉप एनीमेशन

// animate annotation views drop 
func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) { 
     for annView in views { 

      // animate any annotation views except the user pin 
      if !(annView.annotation?.isKind(of: MKUserLocation.self))! { 
       let endFrame = annView.frame 
       annView.frame = endFrame.offsetBy(dx: 0, dy: -500) 
       UIView.animate(withDuration: 0.5, animations: { 
        annView.frame = endFrame 
       }) 
      } 
     } 
संबंधित मुद्दे