gpt4 book ai didi

iphone - 在 iOS 5 中检测用户对 MKMapView 的触摸

转载 作者:可可西里 更新时间:2023-11-01 03:59:46 25 4
gpt4 key购买 nike

我在 ViewController 中有一个 MKMapView,我想在他/她使用这些方法触摸 map 时检测用户的手势:

- (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个方法中的代码都没有达到。

你知道怎么解决吗?

谢谢。

最佳答案

某种形式的 UIGestureRecognizer 可以帮助您。这是在 map View 上使用的点击识别器的示例;如果这不是您要找的,请告诉我。

// 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;
}
}

关于iphone - 在 iOS 5 中检测用户对 MKMapView 的触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7521609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com