gpt4 book ai didi

ios - GestureRecognizer 干扰 w/MapKit 弹出窗口

转载 作者:行者123 更新时间:2023-11-29 11:12:02 27 4
gpt4 key购买 nike

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

所以问题是,我的 map 上方有一个搜索栏。每当用户单击 MapView 时,我都想从搜索框中退出 FirstResponder,因此我添加了一个简单的点击手势响应程序。工作得很好,除了现在不再显示小的灰色细节弹出窗口(只有注释图钉)!我仍然可以点击、缩放、四处移动等。只是没有弹出窗口。

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];
}

是否可以两全其美?

最佳答案

我使用了一个类似于下面的委托(delegate)方法来在应该转到我的自定义 View 的平移手势识别器的触摸和应该转到包含我的自定义 View 的 ScrollView 的触摸之间进行仲裁。类似的东西可能对您有用。

// 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
}
}

关于ios - GestureRecognizer 干扰 w/MapKit 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11092921/

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