我在使用UILongPressGestureRecognizer (可拖式MKPinAnnotationView )时遇到了问题。
我试图制作的行为类似于Maps应用程序。
然而,在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;
}
}发布于 2012-01-12 04:29:41
好了伙计们我解决了。
显然,在子类MKMapView之后,我还添加了一个方法handleLongPress。这种方法显然干扰了MKMapView的MKMapView方法。
只要将我的handleLongPress选择器更改为像handleLongPress2这样的不同名称,它就会像地图应用程序一样工作。
UILongPressGestureRecognizer* lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress2:)];https://stackoverflow.com/questions/8821872
复制相似问题