忽略图形页面:didSelectAnnotationView时长preSS是发生 [英] Ignore mapView:didSelectAnnotationView when long press is occuring

查看:170
本文介绍了忽略图形页面:didSelectAnnotationView时长preSS是发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这一个挣扎。我有一个小地区的许多引脚MapView类。我想忽略注释的MapView的选择,当我在地图上长pressing,如果不管我是在注释视图长pressing。它好像注释越做越触地得分选择,而不是里面摸上来就标注来看,这是烦人。

I am struggling with this one. I have a mapview with many pins in a small area. I want to ignore the mapview's selecting of an annotation when I am long pressing on the map, regardless if i am longpressing on an annotation view. It seems as though the annotation is getting selected on a touchDown, rather than touch up inside on the annotation view, which is annoying.

我添加了一个漫长preSS姿态的MapView:

I have added a longpress gesture to the mapview:

UILongPressGestureRecognizer *longRec = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(addPin:)];
longRec.cancelsTouchesInView = YES;
[self.mapView addGestureRecognizer:longRec];

当我渴望preSS在注释视图这是不认可的。当我preSS下来没有选择注释代表团的呼叫处理和长preSS永远不会触发。

This is not recognized when I long press over an annotation view. As soon as I press down the did select annotation delegation call is processed and the long press never fires.

我试图阻止水龙头手势识别这其中当然不起作用,因为的MapView的手势并非委托给我的地图视图控制器,所以这不工作:

I tried blocking the tap gesture recognizer which of course doesn't work because the mapview's gestures are not delegated to my map view controller, so this doesn't work:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
        return NO;
    }
    return YES;
}

我也尝试添加长preSS姿态注解观为一个黑客,但从来没有得到任何解雇,反正我不喜欢这样的策略。

I also tried adding a longpress gesture to the annotation view as a hack, but that never gets fired either, and I don't like this strategy anyway.

有没有办法阻止的MapView的注解选择时长preSS手势上的MapView未决?

Is there a way to block the mapview's annotation selection when a longpress gesture is pending on the mapview?

推荐答案

想出一个解决方案。基本上继承的MKMapView和实施handleTap和handleLong preSS。

Figured out a solution. Basically subclassing MKMapView and implementing handleTap and handleLongPress.

在那里,我很长一段preSS期间阻止自来水。我也给一点延迟处理其中两个手势同时被识别的情况:

In there I block a tap during a long press. I also give a little delay to handle the case where both gestures are simultaneously recognized:

@implementation KWMapView // :MKMapView

- (void)handleTap:(UITapGestureRecognizer *)tapGesture
{
    CGPoint tapPoint = [tapGesture locationInView:self];
    NSUInteger numberOfTouches = [tapGesture numberOfTouches];

    if (numberOfTouches == 1 && tapGesture.state == UIGestureRecognizerStateEnded) {
        if (!self.blockTap) {
            id v = [self hitTest:tapPoint withEvent:nil];

            if ([v isKindOfClass:[MKAnnotationView class]]) {
                [self addAnnotation:[v annotation]];
                [self selectAnnotation:[v annotation] animated:YES];
            } else {
                [[NSNotificationCenter defaultCenter] postNotificationName:PNMapViewDidTapMap object:tapGesture];
            }
        }
    }
}

- (void)handleLongPress:(UILongPressGestureRecognizer*)sender {
    self.blockTap = YES;

    if (sender.state == UIGestureRecognizerStateBegan) {
        [[NSNotificationCenter defaultCenter] postNotificationName:PNMapViewDropPinGesture object:sender];
    }

    if (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled || sender.state == UIGestureRecognizerStateFailed) {
        double delayInSeconds = .2;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            self.blockTap = NO;
        });
    }
}
@end

这篇关于忽略图形页面:didSelectAnnotationView时长preSS是发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆