GestureRecognizer干扰了MapKit Popup

时间:2012-06-19 00:34:00

标签: ios mapkit uigesturerecognizer

我有一个简单的MapKit应用程序在iOS中运行良好。它有注释,当用户点击它们时,会显示带有标题/副标题的小灰色默认弹出窗口。我甚至在其中添加了一个UIButton视图。

问题是,我的地图上方有一个搜索栏。我想在用户点击MapView时从搜索框中调出第一个响应者,所以我添加了一个简单的点击手势响应器。工作得很好,除了现在不再显示小灰色细节弹出窗口(只有注释引脚)!我仍然可以点击,缩放,移动等等。没有弹出窗口。

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
tap.cancelsTouchesInView = NO;
tap.delaysTouchesBegan = NO;
tap.delaysTouchesEnded = NO;
[mapView addGestureRecognizer:tap];


-(IBAction)tapped:(UITapGestureRecognizer *)geture {
    [searchBar resignFirstResponder];
}

是否有可能拥有两全其美的优势?

1 个答案:

答案 0 :(得分:2)

我使用了类似于以下内容的委托方法来仲裁应该转到我的自定义视图的平移手势识别器的触摸和应该转到包含我的自定义视图的滚动视图的触摸。这样的东西可能适合你。

// the following UIGestureRecognizerDelegate method returns YES by default.
// we modify it so that the tap gesture recognizer only returns YES if
// the search bar is first responder; otherwise it returns NO.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
  if ((gestureRecognizer == self.tapGestureRecognizer) &&
      (gestureRecognizer.view == self.mapView) &&
      [searchBar isFirstResponder])
  {
    return YES;  // return YES so that the tapGestureRecognizer can deal with the tap and resign first responder
  }
  else
  {
    return NO;  // return NO so that the touch is sent up the responder chain for the map view to deal with it
  }
}