当 calloutAccessoryControlTapped 触发时打开视图
当我单击带有导航按钮的注释按钮以返回到我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案。里面:
添加:
然后有一个打开所需视图的功能:
I have found a solution. Inside:
Add:
Then have a function to open the desired view:
-(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];
}