2014-09-05 102 views
4

我在地图上有一个注释。当我选择注释时,我将使用自定义视图来显示标注泡泡。现在,当我点击标注泡泡时,我想要转到新的视图控制器,但当点击视图时标注视图消失。在MK ANNOTATION视图标注气泡上检测到水龙头

-(void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotationView *)view 
{ 
    NSLog(@"selected"); 
    if(![view.annotation isKindOfClass:[MKUserLocation class]]) 
    { 
     CustomInfoWindow *calloutView = [[[NSBundle mainBundle] 
     loadNibNamed:@"infoWindow"owner:self options:nil] objectAtIndex:0]; 
     CGRect calloutViewFrame = calloutView.frame; 
     calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height); 
     calloutView.frame = calloutViewFrame; 
     [calloutView.imagePlace.layer setBorderColor: [[UIColor orangeColor] CGColor]]; 
     [calloutView.imagePlace.layer setBorderWidth: 3.0]; 

     NSData* imageData = [[NSData alloc] initWithContentsOfURL: 
     [NSURL URLWithString:@"http://farm3.staticflickr.com/2926/14605349699_67a1d51b80.jpg"]]; 
     UIImage* image = [[UIImage alloc] initWithData:imageData]; 
     [calloutView.imagePlace setImage:image]; 
     [view addSubview:calloutView]; 
    } 
} 

-(void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view 
{ 
    for (UIView *subview in view.subviews){ 
     [subview removeFromSuperview]; 
    } 
} 
+0

http://stackoverflow.com/questions/3395772/detect-tap-on-calloutbubble-in-mkannotationview – codeIgnitor 2014-09-05 12:09:20

回答

0

我不是专家,但你可能想添加一个UITapGestureRecognizer到你的视图。

使用下面的代码:

UITapGestureRecognizer *tgr = [[UITabGestureRecognizer alloc] initWithTarget:self action:@selector(showNextView)]; 
calloutView.addGestureRecognizer(tgr); 

- (void)showNextView { 
    ... 
} 
0

泡沫没有逻辑,就需要使用标注附件。因此,使用MapView委托方法:

- (void)mapView:(MKMapView *)mv annotationView:(MKAnnotationView *)pin calloutAccessoryControlTapped:(UIControl *)control; 

并在viewForAnnotation委托方法中添加标注。例如:

UIButton *myDetailAccessoryButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
myDetailAccessoryButton.frame = CGRectMake(0, 0, 23, 23); 
myDetailAccessoryButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
myDetailAccessoryButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
pinView.rightCalloutAccessoryView = myDetailAccessoryButton; 

我希望我的回答能帮助你。