我在地图视图中添加了一个点击手势识别器。我的MapView有注释,当我点击注释时,只调用dismissCollectionView
。 DidSelectAnnotation方法没有被调用。点击注释时如何停止tapgesture方法(dismisscollection)调用?任何帮助将不胜感激。
self.m_mapView = [[MKMapView alloc] init];
self.m_mapView.frame = CGRectMake(0, 0, 320, 568);
self.m_mapView.delegate = self;
// MapHeight = self.m_mapView.frameHeight;
m_locationManager = [[CLLocationManager alloc] init];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
[m_locationManager requestWhenInUseAuthorization];
[m_locationManager requestAlwaysAuthorization];
}
self.m_mapView.mapType = MKMapTypeStandard;
[self.m_mapView setUserTrackingMode:MKUserTrackingModeFollow];
[self.m_bgImageView addSubview:self.m_mapView];
m_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
m_locationManager.delegate = self;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissCollectionView)];
tapGesture.numberOfTouchesRequired = 1;
tapGesture.cancelsTouchesInView = NO;
[self.m_mapView addGestureRecognizer:tapGesture];
答案 0 :(得分:0)
如果您希望同时执行这两项操作:设置手势识别器的代理并实施gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
以返回识别器的YES
以及地图视图内部使用的任何内容
如果您希望dismissCollectionView
和mapView:didSelectAnnotationView:
互斥:实施-gestureRecognizer:shouldReceiveTouch:
并检查触摸位置是否在MKAnnotationView
或其中一个子视图。如果位置在所有注释视图之外,则仅返回YES
。