UILongPressGestureRecognizerとドラッグ可能なMKPinAnnotationViewを併用する際に問題があります。UILongPressGestureRecognizerをMKMapViewのドラッグ可能なMKPinAnnotationViewとともに使用する
私が作成しようとしている動作は、マップアプリケーションに似ています。
- ピンをドラッグすることができます。
- 長い押し/タップがあると、ピンが落ちます。
しかし、長いプレスがMKPinAnnotationViewの枠外で認識されているという問題があります。ピンがドラッグ可能でない場合、ピンを落とすための長い押しのけのジェスチャーはうまく動作します。しかし、ピンがドラッグ可能な場合、私はピンを落とすことができるように、長いプレスジェスチャ認識装置を認識させることができません。
アイデア?ところで
は、私は、長押しジェスチャーが認識されるとピンがドロップされます。この場合
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
ように、長押し認識のためのデリゲートを設定しようとしたが、のドラッグいますピンはもはや機能しません。 MapView(MKMapViewのサブクラス)の
スニペット
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// init the gesture recognizer
UILongPressGestureRecognizer* lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 0.5f; //user needs to press for 2 seconds
lpgr.delegate = self;
[self addGestureRecognizer:lpgr];
[lpgr release];
//add some initial annotation
Marker *_annotation = [[Marker alloc] initWithCoordinate:_location];
[_annotation titleWithString:@"some title"];
[self addAnnotation:_annotation];
}
return self;
}
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
{
return;
}
CGPoint touchPoint = [gestureRecognizer locationInView:self];
CLLocationCoordinate2D touchMapCoordinate = [self convertPoint:touchPoint toCoordinateFromView:self];
// add marker to self-map
// Marker is subclass of MKAnnotation
Marker *_annotation = [[Marker alloc] initWithCoordinate:_location];
[_annotation titleWithString:@"some title"];
[self addAnnotation:_annotation];
}
- (MKAnnotationView *)mapView:(MKMapView *)mView viewForAnnotation:(id<MKAnnotation>) annotation {
if([annotation isMemberOfClass:[Marker class]]) {
// use MKPinAnnotationView for the view
MKPinAnnotationView *_pin = (MKPinAnnotationView *) [mView dequeueReusableAnnotationViewWithIdentifier:@"spot_pin"];
if (_pin == nil)
{
_pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"spot_pin"] autorelease];
}
else
{
_pin.annotation = annotation;
}
[_pin setDraggable:YES];
[_pin setSelected:YES animated:YES];
[_pin setCanShowCallout:YES];
return _pin;
} else {
return nil;
}
}
私は同じことに固執しています。ピンをうまく落とすが、その注釈をどのようにドラッグするのか.please hellp me – user100