如何檢測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