开发者

Open a view when calloutAccessoryControlTapped triggered

How can I open a view when I clicked on annotation's button with a navigation button to go back to my mapkit and pass some parameters to 开发者_开发问答the view?

Regards


I have found a solution. Inside:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

Add:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[btn addTarget:self action:@selector(pinTouched:) forControlEvents:UIControlEventTouchUpInside];

Then have a function to open the desired view:

-(void)pinTouched:(UIButton *)sender
{
myView.transform  = CGAffineTransformMakeScale(.01, .01);
[self.view addSubview:myView];
}


-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {

... ... ...

//important

//otherwise calloutAccessoryControlTapped not called

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;

....

....

return pin;

}

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

// annotation tapped

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

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜