Ios 检测MK注释视图标注编号气泡上的点击
我在地图上有注释。选择注释时,将显示带有自定义视图的详图索引编号。现在,当我单击详图索引编号时,我想转到新的视图控制器,但单击视图时详图索引视图消失Ios 检测MK注释视图标注编号气泡上的点击,ios,objective-c,mkmapview,Ios,Objective C,Mkmapview,我在地图上有注释。选择注释时,将显示带有自定义视图的详图索引编号。现在,当我单击详图索引编号时,我想转到新的视图控制器,但单击视图时详图索引视图消失 -(void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotationView *)view { NSLog(@"selected"); if(![view.annotation isKindOfClass:[MKUserLocation class]])
-(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];
}
}
我不是专家,但您可能希望在视图中添加UITapGestureRecognitor 使用以下代码:
UITapGestureRecognizer *tgr = [[UITabGestureRecognizer alloc] initWithTarget:self action:@selector(showNextView)];
calloutView.addGestureRecognizer(tgr);
及
气泡没有逻辑,需要使用详图索引附件。因此,请使用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;
我希望我的回答能帮助你
UIButton *myDetailAccessoryButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
myDetailAccessoryButton.frame = CGRectMake(0, 0, 23, 23);
myDetailAccessoryButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailAccessoryButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
pinView.rightCalloutAccessoryView = myDetailAccessoryButton;