Ale*_*lez 25 mkmapview mkannotation mkannotationview ios
我正在使用MKMapView和MKAnnotationView.
我在地图上有一个注释.当用户点击它时,会显示callOut Bubble.再次点击注释(并且callOut Bubble可见)我需要更改为另一个视图.
如何检测第二个水龙头或气泡中的水龙头?
Dol*_*lbz 11
你初始化时可以添加手势识别器MKAnnotationView吗?
这是里面的代码 dequeueReusableAnnotationViewWithIdentifier:
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(calloutTapped:)];
[theAnnotationView addGestureRecognizer:tapGesture];
[tapGesture release];
Run Code Online (Sandbox Code Playgroud)
手势识别器的方法:
-(void) calloutTapped:(id) sender {
// code to display whatever is required next.
// To get the annotation associated with the callout that caused this event:
// id<MKAnnotation> annotation = ((MKAnnotationView*)sender.view).annotation;
}
Run Code Online (Sandbox Code Playgroud)
这是Dhanu答案的快速版本,包括从所选项目中获取数据以传递给下一个视图控制器:
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
let gesture = UITapGestureRecognizer(target: self, action: #selector(MyMapViewController.calloutTapped(_:)))
view.addGestureRecognizer(gesture)
}
func calloutTapped(sender:UITapGestureRecognizer) {
guard let annotation = (sender.view as? MKAnnotationView)?.annotation as? MyAnnotation else { return }
selectedLocation = annotation.myData
performSegueWithIdentifier("mySegueIdentifier", sender: self)
}
Run Code Online (Sandbox Code Playgroud)
小智 6
要在用户单击Annotation视图后点击callout按钮,请在didSelectAnnotationView中添加UITapGestureRecognizer.这样,您可以在不需要附件视图的情况下实现对标注的点击.
然后,您可以从发件人处获取注释对象以进行进一步操作.
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(calloutTapped:)];
[view addGestureRecognizer:tapGesture];
}
-(void)calloutTapped:(UITapGestureRecognizer *) sender
{
NSLog(@"Callout was tapped");
MKAnnotationView *view = (MKAnnotationView*)sender.view;
id <MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
[self performSegueWithIdentifier:@"annotationDetailSegue" sender:annotation];
}
}
Run Code Online (Sandbox Code Playgroud)
尝试在不更改 UIButtonTypeDetailDisclosure 类型的情况下为按钮设置自定义图像。
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[detailButton setImage:[UIImage imageNamed:@"icon"] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12107 次 |
| 最近记录: |