- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
除了 MKMapView 已使用的手势识别器之外,我还尝试实现自己的手势识别器。现在我可以点击 map 并设置图钉。这种行为是由我的 UITapGestureRecognizer 实现的。当我点击已经存在的引脚时,我的手势识别器不执行任何操作,而是显示该引脚的标注气泡。 UIGestureRecognizerDelegate 看起来像这样:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (gestureRecognizer == self.tapRecognizer)
{
bool hitAnnotation = false;
int count = [self.mapView.annotations count];
int counter = 0;
while (counter < count && hitAnnotation == false )
{
if (touch.view == [self.mapView viewForAnnotation:[self.mapView.annotations objectAtIndex:counter]])
{
hitAnnotation = true;
}
counter++;
}
if (hitAnnotation)
{
return NO;
}
}
return YES;
}
这很好用。我唯一的问题是引脚和双击的标注气泡。通常双击用于放大。这仍然有效,但除此之外,我还获得了一个新的图钉。有什么办法可以避免这种情况吗?
另一个问题发生在图钉的标注气泡上。我可以通过点击图钉来打开气泡,而无需在此位置设置新图钉(请参见上面的代码),但是当我想通过点击图钉来关闭气泡时,会设置另一个图钉。我的问题是,如果用户点击标注气泡,我无法检查 touch.view ,因为据我所知,它不是常规的 UIView 。对于这个问题有什么想法或解决方法吗?
谢谢
最佳答案
我遇到了与您的第一个问题相同的问题:区分 MKMapView
中的双击和单击。我所做的如下:
[doubleTapper release];
doubleTapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapDoubleTapped:)];
doubleTapper.numberOfTapsRequired = 2;
doubleTapper.delaysTouchesBegan = NO;
doubleTapper.delaysTouchesEnded = NO;
doubleTapper.cancelsTouchesInView = NO;
doubleTapper.delegate = self;
[mapTapper release];
mapTapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapTapped:)];
mapTapper.numberOfTapsRequired = 1;
mapTapper.delaysTouchesBegan = NO;
mapTapper.delaysTouchesEnded = NO;
mapTapper.cancelsTouchesInView = NO;
[mapTapper requireGestureRecognizerToFail:doubleTapper];
然后实现以下委托(delegate)方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
使用 requireGestureRecognizerToFail:
允许应用区分单击和双击,并实现 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
确保双击仍转发到 MKMapView
以便它继续正常缩放。请注意,doubleTapper 实际上并没有执行任何操作(在我的例子中,除了记录调试消息)。它只是一个虚拟的 UIGestureRecognizer
,用于帮助区分单击和双击。
关于iPhone:将 MKMapView 与另一个 UITapGestureRecognizer 相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7014107/
在我当前设计的应用程序中,我有一个带有覆盖层的 MKMapView (顺便说一句,自定义的 MKPolylines),我希望能够检测到触摸事件这些覆盖层并为每个覆盖层分配特定的操作。有人可以帮我解决这
我在我的 .xib 上放置了一个 MKMapView。 它工作正常,但我需要 map 根据罗盘方向旋转? 我读过有关“指南针模式”的内容。 也许我需要将 compassMode 的 MKMapView
我有一个带有注册委托(delegate)的 MKMapView,因此我可以监听区域更改事件(具体来说,regionDidChangeAnimated)。我正在寻找一种可靠的方法来判断区域更改事件是用户
我正在尝试将 MKAnnotationView 添加到 MKMapView 但我做不到……有人能帮我吗? 这是我的代码: override func viewDidLoad() { super
我想像照片应用程序中那样隐藏和显示导航栏但不会丢失 MKMapView 的功能。用户仍然应该能够双击进行缩放、捏合和缩放,并能够选择注释。 我试过: UITapGestureRecognizer*
我在 MKMapView 上有一个 MKCircle。它是用户可拖动的,但如果用户拖动圆圈外的区域, map 应该会移动。 - (IBAction)createPanGestureRecognizer
我正在开发一款与 map 配合使用的 iPhone 应用程序。在此应用程序中,我需要根据纬度和经度显示一些 parking 位(地址)。至此,我成功完成了,但我想显示相对于用户方向(SE、SW、NE、
如何比较 MKMapView 的当前跨度?我正在使用以下代码: - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)a
我们在我们的一个应用程序中看到了意外行为 - 我们在一个屏幕上显示 map View 上的注释,用户可以通过单击按钮更改显示的注释。 当我们用 iOS7 重建应用程序时,屏幕会定期卡住,即一旦下面的代
我正在尝试创建一个带有 MKMapView 和一个导航到用户位置的按钮的 SwiftUI View 。以下是我的全部代码。我创建了一个名为 MapView 的 View ,它符合 UIViewRepr
我的代码在iOS 7到8上运行良好。昨天进行了更新,我的图钉上的自定义图像已替换为标准的图钉图像。 有什么建议? 我的代码: extension ViewController: MKMapViewDe
我可以使用 MKMApView 组件创建一个 iOS 商业应用程序(在应用程序商店中花费几美元下载)吗? 我知道它是基于 Google 图片,所以...我不知道。 最佳答案 当然,MapKit 已用于
我有用户位置和边界。边界有8个坐标。我需要检查用户是否在边界内。我正在 iPhone 中使用 MapView。 提前致谢。 最佳答案 使用 Map Kit 中的一些内置函数来执行此操作的一种方法是将边
我有一个 MkMapView,并希望将 map 保持在用户位置的中心,就像按下范围按钮时 iPhone map 应用程序所做的那样。 我使用 setCenterCoordinate 方法,因为我不需要
浏览了这里的一些问题后,我对缩放级别和 MKMapView 有了一个大概的了解。然后我发现了这个很棒的博客: http://troybrant.net/blog/2010/01/set-the-zoo
我有一个使用以下代码删除 pin 的功能: ParkPlaceMark *placemark=[[ParkPlaceMark alloc] initWithCoordinate:location];
双击 MKMapView 时:放大。 但是如何缩小呢? 最佳答案 总是使用两根手指来放大和缩小。在模拟器上,您需要按住选项键才能在模拟屏幕上显示“两根手指”(我认为这是 Alt 键,但我在 Mac 上
释放 MKMapView 后,我遇到了奇怪的(?)崩溃。 MKMapView 是我的 View Controller 中的 subview ,在我从导航堆栈中删除该 View 并释放它后,应用程序崩溃
我通过单击按钮缩小 map 。 因此,本地图完全缩小时,如果我尝试再次缩小它,那么它在设置区域时会崩溃。 不确定,但是,有没有办法检测 map 是否达到最大缩放限制? 这是我缩小 map 的代码 -(
我需要获得某种比例因子,它可以告诉我 map 缩放了多少(每当区域发生变化时)。 我的第一个想法是使用跨度的纬度或经度增量值。我会跟踪“旧”值,然后在 map 区域发生变化时更新该值,并将比率与旧值进
我是一名优秀的程序员,十分优秀!