【问题标题】:iOS : Show the Callout view on moving piniOS:在移动图钉上显示标注视图
【发布时间】:2017-01-19 07:06:56
【问题描述】:

我已经实现了与 Uber iOS 应用程序相同的功能,用于根据路线和动画移动图钉。

问题:当我在图钉移动时单击它时,我无法获得MKMapViewdidSelectAnnotationView 代表。但是当 pin 是稳定的意味着不移动时,它就会被调用。

代码:创建图钉

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

【问题讨论】:

    标签: ios objective-c mkannotationview callout


    【解决方案1】:

    试试这个。

    我认为您看到的行为是因为默认情况下,用户交互在新的块调用中被禁用持续动画。

    您可以通过传递 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];
    

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多