我不确定我做错了什么,但我试图抓住一个MKMapView物体.我通过创建以下类来继承它:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewWithTouches : MKMapView {
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event;
@end
Run Code Online (Sandbox Code Playgroud)
并实施:
#import "MapViewWithTouches.h"
@implementation MapViewWithTouches
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event {
NSLog(@"hello");
//[super touchesBegan:touches withEvent:event];
}
@end
Run Code Online (Sandbox Code Playgroud)
但看起来当我使用这个类时,我在控制台上看不到任何内容:
MapViewWithTouches *mapView = [[MapViewWithTouches alloc] initWithFrame:self.view.frame];
[self.view insertSubview:mapView atIndex:0];
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?
我正在尝试计算特定注释(如用户位置的蓝色圆圈)或MKPinAnnotation是否在mapview上的MKPolygon图层内.
有什么建议来实现这个目标
基于我在这个SO问题上找到的内容(在MKMapView的叠加上触摸事件),我已经实现了一种拦截MKPolygon上的轻击手势的方法.
它在我们的应用程序中运行良好,该应用程序是使用Xcode 4.6.3针对iOS 6构建的.但是当我在iOS 7设备上尝试它时停止工作.
特别
CLLocationCoordinate2D coord = [neighborhoodMap_ convertPoint:point
toCoordinateFromView:neighborhoodMap_];
// We get view from MKMapView's viewForOverlay.
MKPolygonView *polygonView = (MKPolygonView*) view;
CGPoint polygonViewPoint = [polygonView pointForMapPoint:mapPoint];
BOOL mapCoordinateIsInPolygon = CGPathContainsPoint(polygonView.path,
NULL,
polygonViewPoint,
NO);
Run Code Online (Sandbox Code Playgroud)
由于某种原因,即使给定的坐标在MKPolygonView中,对CGPathContainsPoint的调用也不再返回YES.不确定是否有人遇到过这个问题,但我很感激您的任何见解.
谢谢!