Iphone 在iOS 5中检测用户对MKMapView的触摸
我在ViewController中有一个Iphone 在iOS 5中检测用户对MKMapView的触摸,iphone,objective-c,ios,mkmapview,touch-event,Iphone,Objective C,Ios,Mkmapview,Touch Event,我在ViewController中有一个MKMapView,希望在用户使用以下方法触摸地图时检测其手势: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
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>>
iOS 5.0之前的触摸交付方法依赖于转发。转发-触摸已取消:带事件:至
以上4种方法中的代码均未达到
你知道怎么修吗
谢谢。某种形式的
UIgestureRecognitor
可以帮助您。下面是一个在地图视图上使用的点击识别器的示例;如果这不是你要找的,请告诉我
// 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;
}
}
目前还不能对iOS 5发表评论,但对于3.2到4,使用UIGestureRecognitor而不是Touchs方法可能更容易。。。检查此链接