当我单击带有导航按钮的注释按钮以返回我的 mapkit 并将一些参数传递给视图时,如何打开视图?
问候
我找到了解决方案。里面:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
添加:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[btn addTarget:self action:@selector(pinTouched:) forControlEvents:UIControlEventTouchUpInside];
然后具有打开所需视图的功能:
-(void)pinTouched:(UIButton *)sender
{
myView.transform = CGAffineTransformMakeScale(.01, .01);
[self.view addSubview:myView];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
…………
//重要的
//否则calloutAccessoryControlTapped不被调用
pin.canShowCallout = YES;
pin.calloutOffset = CGPointMake(-10, -10);
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"some.png"]];
leftIconView.backgroundColor = [UIColor clearColor];
leftIconView.contentMode = UIViewContentModeScaleAspectFit;
leftIconView.frame = CGRectMake(0, 0, 40, 40);
pin.leftCalloutAccessoryView = leftIconView;
……
……
返回销;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// 注释被点击
浮动视图宽度 = 100;
浮动视图高度 = 300;
浮动视图X = 50;
浮动视图Y = 50;
CGRect viewRect = CGRectMake(viewX,viewY, viewWidth, viewHeight);
UIView *viewSub = [[UIView alloc] initWithFrame:viewRect];
viewSub.backgroundColor = [UIColor redColor];
viewSub.tag = 666;
[self.view addSubview:viewSub];
[self.view bringSubviewToFront:viewSub];
}