触发calloutAccessoryControlTapped时打开视图

时间:2011-06-09 11:15:34

标签: xcode annotations mapkit callouts

当我点击带有导航按钮的注释按钮返回我的mapkit并将一些参数传递给视图时,如何打开视图?

此致

2 个答案:

答案 0 :(得分:2)

我找到了解决方案。内:

- (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];
}

答案 1 :(得分:0)

- (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;

...

...

返回pin;

}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

点击

//注释

float viewWidth = 100;

float viewHeight = 300;

float viewX = 50;

float viewY = 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];

}