Tuy*_* GB 6 iphone objective-c mkmapview touch-event ios
我有一个MKMapViewViewController,并希望在他/她用这些方法触摸地图时检测用户的手势:
- (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;
Run Code Online (Sandbox Code Playgroud)
该应用程序适用于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>>
Run Code Online (Sandbox Code Playgroud)
并且未达到上述4种方法中的代码.
你知道怎么解决吗?
谢谢.
某种形式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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3328 次 |
| 最近记录: |