gpt4 book ai didi

ios - 在不中断双击缩放的情况下单击 MKMapView

转载 作者:可可西里 更新时间:2023-11-01 03:10:27 27 4
gpt4 key购买 nike

当用户在 map 上单击时,我想在我的 MKMapView 上放置一个图钉。我有密码工作,我有单击工作,但当我双击缩放时,我先单击一下。这是我获取识别器设置的代码:

    self.doubleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleDoubleTap:)];
self.doubleTap.numberOfTapsRequired = 2;
self.doubleTap.numberOfTouchesRequired = 1;
[mapView_ addGestureRecognizer:doubleTap_];

self.singleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleGesture:)];
self.singleTap.numberOfTapsRequired = 1;
self.singleTap.numberOfTouchesRequired = 1;
[self.singleTap requireGestureRecognizerToFail: doubleTap_];
[mapView_ addGestureRecognizer:singleTap_];

现在,这并不奇怪,引用 Apple 的话:

Note: In the case of the single-tap versus double-tap gestures, if a single-tap gesture recognizer doesn’t require the double-tap recognizer to fail, you should expect to receive your single-tap actions before your double-tap actions, even in the case of a double tap. This is expected and desirable behavior because the best user experience generally involves stackable actions.

所以我将 requireGestureRecognizerToFail 添加到我的单击识别器中。

[singleTap requireGestureRecognizerToFail: doubleTap];

这确保我的单击识别器不会得到双击。

但是……

现在我的双击识别器得到了双击,而 MKMapView 没有得到它们。我已经尝试在识别器中将 cancelsTouchesInView 设置为 NO,但这也没有帮助。

所以我需要一种方法来防止我的单击识别器获得双击(这似乎不太可能)或将我的双击事件发送到我的 mapView。

最佳答案

在 iOS 8 上完美运行,双击操作无效

  - (void)viewDidLoad 
{
[super viewDidLoad];

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:nil];
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired = 1;
[self.mapView addGestureRecognizer:doubleTap];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
[singleTap requireGestureRecognizerToFail: doubleTap];
[self.mapView addGestureRecognizer:singleTap];
}

- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateEnded)
return;
//Do your work ...
}

关于ios - 在不中断双击缩放的情况下单击 MKMapView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13571595/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com