2017-01-19 7 views
5

पर कॉलआउट दृश्य दिखाएं मैंने एनीमेशन के साथ मार्ग के अनुसार पिन को स्थानांतरित करने के लिए उबर iOS एप्लिकेशन के समान कार्यक्षमता लागू की है।आईओएस: पिन

मुद्दे: जब मैं पिन पर क्लिक करें, जबकि यह तो बढ़ रहा है मैं MKMapView की didSelectAnnotationView प्रतिनिधि प्राप्त करने में सक्षम नहीं हूँ। लेकिन जब पिन स्थिर होता है तो आगे बढ़ने का मतलब नहीं होता है।

कोड: पिन

-(MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id<MKAnnotation>)annotation { 

    if([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 

    else { 

     NSString *annotationIdentifier = @"CustomViewAnnotation"; 

     AnnotationView * annotationView = (AnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier]; 

     if(annotationView == nil) { 

      annotationView = [[AnnotationView alloc] initWithAnnotation:annotation 
                     reuseIdentifier:annotationIdentifier]; 
      UIImage *pinIcon = [UIImage imageNamed:@"carIcon"]; 
      annotationView.btnInfo = [[UIButton alloc] init]; 
      annotationView.frame = CGRectMake(0.0f, 0.0f, pinIcon.size.width, pinIcon.size.height); 
      annotationView.btnInfo.frame = annotationView.frame; 
      [annotationView.btnInfo setBackgroundImage:pinIcon forState:UIControlStateNormal]; 
      [annotationView addSubview:annotationView.btnInfo]; 
      [annotationView.btnInfo setUserInteractionEnabled:NO]; 
     } 

     else 
      annotationView.annotation = annotation; 

     annotationView.enabled = YES; 
     annotationView.canShowCallout = YES; 

     return annotationView; 
    } 
} 

बनाएं अद्यतन समन्वय

- (void)updateLocation { 

    CLLocationCoordinate2D oldLocation; 
    CLLocationCoordinate2D newLocation; 

    oldLocation.latitude = [self convertStringToFloat:self.arrayCSV[self.index-1][@"Latitude"]]; 
    oldLocation.longitude = [self convertStringToFloat:self.arrayCSV[self.index-1][@"Longitude"]]; 
    newLocation.latitude = [self convertStringToFloat:self.arrayCSV[self.index][@"Latitude"]]; 
    newLocation.longitude = [self convertStringToFloat:self.arrayCSV[self.index][@"Longitude"]]; 
    float getAngle = [self angleFromCoordinate:oldLocation toCoordinate:newLocation]; 

    CLLocation *oldInfo = [[CLLocation alloc] initWithLatitude:oldLocation.latitude longitude:oldLocation.longitude]; 
    CLLocation *newInfo = [[CLLocation alloc] initWithLatitude:newLocation.latitude longitude:newLocation.longitude]; 

    [UIView animateWithDuration:3 
     animations:^{ 
      myAnnotation.coordinate = newLocation; 
      AnnotationView *annotationView = (AnnotationView *)[self.mapView viewForAnnotation:myAnnotation];     
      annotationView.transform = CGAffineTransformMakeRotation(getAngle); 
    }]; 
} 

उत्तर

2

इस प्रयास करें।

मुझे लगता है कि आप जो व्यवहार देख रहे हैं वह है क्योंकि डिफ़ॉल्ट रूप से, उपयोगकर्ता इंटरैक्शन नई ब्लॉक कॉल के साथ अक्षम अवधि अवधि एनीमेशन है।

आप नीचे दिए गए जैसे UIViewAnimationOptionAllowUserInteraction पारित करके इस ओवरराइड कर सकते हैं:

[UIView animateWithDuration:3 
    delay:0 
    options:UIViewAnimationOptionAllowUserInteraction 
    animations:^{ 
     myAnnotation.coordinate = newLocation; 
     AnnotationView *annotationView = (AnnotationView *)[self.mapView viewForAnnotation:myAnnotation];     
     annotationView.transform = CGAffineTransformMakeRotation(getAngle); 
    } 
completion:nil]; 
+0

आप मेरा दिन धन्यवाद @wolverine बचा लिया। –

संबंधित मुद्दे