当 calloutAccessoryControlTapped 触发时打开视图

发布于 2024-11-14 12:45:00 字数 67 浏览 2 评论 0原文

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

问候

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

虫児飞 2024-11-21 12:45:00

我找到了解决方案。里面:

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

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];
}
迟到的我 2024-11-21 12:45:00

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)注释 {

...
...
...

//重要

//否则 calloutAccessoryControlTapped 不会被调用

pin.canShowCallout = YES;

pin.calloutOffset = CGPointMake(-10, -10);

UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"some.png"]];

leftIconView.backgroundColor = [UIColor 清除颜色];

leftIconView.contentMode = UIViewContentModeScaleAspectFit;

leftIconView.frame = CGRectMake(0, 0, 40, 40);

pin.leftCalloutAccessoryView = leftIconView;

......

返回

销;

}

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

// 注释被点击

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

}

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

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文