我在ViewController中有一个MKMapView
,并希望在他/她用这些方法触摸地图时检测用户的手势:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
该应用程序适用于iOS 3,iOS 4 但是当我在iOS 5上运行iPhone调试应用程序时,我看到了这样的消息:
Pre-iOS 5.0 touch delivery method forwarding relied upon. Forwarding -touchesCancelled:withEvent: to <MKAnnotationContainerView: 0x634790; frame = (0 0; 262144 262144); autoresizesSubviews = NO; layer = <CALayer: 0x634710>>
并且未达到上述4种方法中的代码。
你知道怎么解决吗?
感谢。
答案 0 :(得分:1)
某种形式的UIGestureRecognizer
可以帮到你。这是在地图视图中使用的点击识别器的示例;如果这不是你想要的,请告诉我。
// in viewDidLoad...
// Create map view
MKMapView *mapView = [[MKMapView alloc] initWithFrame:(CGRect){ CGPointZero, 200.f, 200.f }];
[self.view addSubview:mapView];
_mapView = mapView;
// Add tap recognizer, connect it to the view controller
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapViewTapped:)];
[mapView addGestureRecognizer:tapRecognizer];
// ...
// Handle touch event
- (void)mapViewTapped:(UITapGestureRecognizer *)recognizer
{
CGPoint pointTappedInMapView = [recognizer locationInView:_mapView];
CLLocationCoordinate2D geoCoordinatesTapped = [_mapView convertPoint:pointTappedInMapView toCoordinateFromView:_mapView];
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:
/* equivalent to touchesBegan:withEvent: */
break;
case UIGestureRecognizerStateChanged:
/* equivalent to touchesMoved:withEvent: */
break;
case UIGestureRecognizerStateEnded:
/* equivalent to touchesEnded:withEvent: */
break;
case UIGestureRecognizerStateCancelled:
/* equivalent to touchesCancelled:withEvent: */
break;
default:
break;
}
}