2014-09-05 105 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; 

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