2012-06-19 60 views
1

我有一個簡單的MapKit應用程序在iOS中工作正常。它有註釋,當用戶點擊它們時,小灰色的默認彈出窗口會顯示標題/副標題。我甚至在其中添加了一個UIButton視圖。GestureRecognizer干擾與MapKit彈出窗口

所以問題是,我的地圖上方有一個搜索欄。每當用戶點擊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]; 
} 

是否有可能獲得兩全其美?

回答

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 
    } 
} 
+0

好的交易,謝謝你=] –