![](/img/trans.png)
[英]LongPress gesture doesn't work on iOS 5 and iOS 5.1 (but works on iOS 6)
[英]longpress gesture recognizer doesn't work on user location (MKuserlocation) on map view - iOS
我的應用程序中有一個MapView。 Showuserlocation處於活動狀態。 我添加了GestureRecognizer進行長按。 一切正常。
通過利弊,當我觸摸用戶的注釋(藍色圓圈)時,不接收手勢事件。
如何攔截用戶注釋上的手勢?
謝謝您的幫助。
您可以通過修改上述代碼中的微小更改來添加手勢以檢測長按。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
UILongPressGestureRecognizer* _longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressDetected:)];
_longPressRecognizer.minimumPressDuration = 0.0;
_longPressRecognizer.accessibilityValue = [NSString stringWithFormat:@"%d",totalMenues];
[pinView addGestureRecognizer:_longPressRecognizer];
}
- (void) longPressDetected:(UIGestureRecognizer*) gestureRecognizer
{
}
您沒有在注釋上添加手勢。因此您需要為每個注釋添加手勢。由於有兩種方法,因此無需向注釋添加手勢。
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
如果你想的話
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation)annotation
{
// Reuse or create annotation view
UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTapRecgonized:)];
longTap.delegate = self;
[annotationView addGestureRecognizer:longTap];
}
- (void)longTapRecognized:(UITapGestureRecognizer *)recognizer
{
// Handle double tap on annotation view
}
你有沒有實現UIGestureRecognizerDelegate
后續方法?
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
該方法應返回YES,因此手勢識別器可與其他人一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.