Обнаружение прикосновений пользователя к MKMapView в iOS 5

У меня есть MKMapView в ViewController, и я хотел бы обнаруживать жесты пользователей, когда они касаются карты с помощью следующих методов:

- (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, но когда я отлаживаю приложение с iPhone, работающим на iOS 5, я вижу это сообщение:

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 методах не достигается.

Вы знаете, как это исправить?

Спасибо.


person Tuyen Nguyen GB    schedule 22.09.2011    source источник
comment
Пока не могу комментировать iOS 5, но для версий 3.2–4 может быть проще использовать UIGestureRecognizer вместо методов касаний.   -  person    schedule 23.09.2011
comment
stackoverflow.com/questions/1049889/ .. Проверьте эту ссылку   -  person Kalpesh    schedule 19.10.2012


Ответы (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;
    }
}
person Dany Joumaa    schedule 25.10.2012