如何检测mapview是否被点击,这不是obj-c中的注释?在mkmapview上检测不是注释的轻击手势?
0
A
回答
0
尝试UITapGestureRecognizer:
UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(mapDidTap:)];
[mapView addGestureRecognizer: tapGesture];
而且
-(void)mapDidTap:(UITapGestureRecognizer *)gestureRecognizer {
//do something when map is tapped
}
+0
我正在使用这个代码,并且mapDidTap:永远不会被调用。 –
0
下面的代码检测地图的龙头,在该位置增加了一个地图标记:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *fingerTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleMapFingerTap:)];
fingerTap.numberOfTapsRequired = 1;
fingerTap.numberOfTouchesRequired = 1;
[self.mapView addGestureRecognizer:fingerTap];
}
- (void)handleMapFingerTap:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"handleMapFingerTap gesture: %@", gestureRecognizer);
if (gestureRecognizer.state != UIGestureRecognizerStateEnded) {
return;
}
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchMapCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = touchMapCoordinate;
pa.title = @"Hello";
[self.mapView addAnnotation:pa];
}
0
我在我们的案例中,通过广告修复了这个问题, 将手势同步到注释视图和地图视图。
加点触手势映射
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.hideFilterView))
self.mapView.addGestureRecognizer(tapGesture)
//override "viewFor annotation:" something like this
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var annotationView = self.mapView.dequeueReusableAnnotationView(withIdentifier: "Pin")
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "Pin"
annotationView?.canShowCallout = false
}else{
annotationView?.annotation = annotation
}
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.didTapPin(onMap:)))
annotationView?.addGestureRecognizer(tapGesture)
return annotationView
}
//then don't override
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
}
所以所有引脚选择将被处理使用自来水手势。 你可以分别检测地图和别针。
相关问题
- 1. 如何选择轻击手势而不是画手势?
- 2. MKMapView在点击注释气球时检测到
- 3. iOS - 忽略轻击手势
- 4. 如何检测自定义UIScrollView上的水平轻扫手势?
- 5. MKMapView注释点击事件
- 6. UIPopoverPresentationController不会在标题视图上禁用轻击手势
- 7. UITapGestureRecognizer中的objective c mkmapview如何测试他们是否在注释上点击
- 8. MKMapView上的手势识别 - iPhone
- 9. Android手势检测
- 10. 在Adobe AIR for Mobile上模拟摇动手势/轻推手势?
- 11. MKMapview注释
- 12. 平移手势 - 轻扫手势冲突
- 13. 轻扫手势iphone
- 14. 手势检测器上的OnUp事件
- 15. 在放大的MKMapView上合并注释
- 16. MKMapView不刷新注释
- 17. Air for iOS:测试我的mac上的轻扫手势
- 18. 在工具栏上检测到手势检测
- 19. Swift - 我如何检测轻扫手势距离放弃?
- 20. Android libgdx使用手势监听器轻扫左右检测
- 21. setUserTrackingMode在MKMapView上注释很慢
- 22. Android:手势检测器不会捕获手势
- 23. 双击UICollectionViewCell上的手势?
- 24. 调整MkMapView注释
- 25. iOS - MKMapView - Buggy注释
- 26. 检测手势加速计
- 27. 使用Kinect手势检测
- 28. Android ViewFlipper +手势检测器
- 29. Android手势检测问题
- 30. LinearLayout和手势检测器
奇怪的是,您只需添加通常的点击检测代码 - 似乎MapView没有“内置”的概念! – Fattie