2015-12-31 19 views
0

我在下面的代表中使用了这个,并在注释中设置图像。当点击注释时,它的didselectannotation委托不会被调用。但是,当我使用默认然后它的工作。请建议是否有人可以在这方面提供帮助。当点击注解地图位置不缩放

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

static NSString *defaultPinID = @"Annotation"; 
    pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
    if (pinView == nil) 
     pinView = [[MKAnnotationView alloc] 
        initWithAnnotation:annotation reuseIdentifier:defaultPinID]; 

    UIImage *originalImage = [UIImage imageNamed:@"map.png"]; 
    pinView.canShowCallout = YES; 
    pinView.image = [self drawImage:originalImage inRect:CGRectMake(0, 0, 106, 148)]; 
    pinView.calloutOffset = CGPointMake(0, -5); 

    UIImageView *profileImageView = [[UIImageView alloc]init]; 
    profileImageView.frame = CGRectMake(6, 7, 40, 40); 
    [profileImageView setImage:[UIImage imageNamed:@"user.png"]]; 
    [profileImageView setBackgroundColor:[UIColor whiteColor]]; 
    [self setRoundedAvatar:profileImageView toDiameter:40 atView:self.view]; 
    [pinView addSubview:profileImageView]; 
+0

检查此问题http://stackoverflow.com/questions/29179473/mkannotationview-subviews – Muneeba

回答

0

我已经完成了这个使用gestureRecognizer PinView。

UITapGestureRecognizer *tapLocation = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRecognizerShouldBeginFocusMap:)]; 
    tapLocation.numberOfTapsRequired=1; 
    [pinView addGestureRecognizer:tapLocation]; 

- (BOOL)gestureRecognizerShouldBeginFocusMap:(UIGestureRecognizer *)gestureRecognizer 
{ 

     MKMapRect visibleMapRect = self.mapView.visibleMapRect; 
     NSSet *visibleAnnotations = [self.mapView annotationsInMapRect:visibleMapRect]; 

     for (MyAnnotation *annotation in visibleAnnotations){ 

      [self setCenterCoordinate:annotation.coordinate zoomLevel:18 animated:YES]; 

     } 

     return YES; 
} 
相关问题