繁体   English   中英

长按每次点击会下降2个针脚

[英]Long press drops 2 pins with each tap

我通过长按让我的应用程序掉了针,我想用户只允许掉两个针,并且它可以正常工作..但是,每当我在模拟器中点击以添加一个针时,它都会增加两个针(不仅是一个)。编码:

-(void) handleLongPressGesture:(UIGestureRecognizer*)sender
{
    if (pinId < 3) {
        // Here we get the CGPoint for the touch and convert it to
        // latitude and longitude coordinates to display on the map

        CGPoint point = [sender locationInView:self.mapView];       
        CLLocationCoordinate2D coord = [self.mapView convertPoint:point
                                            toCoordinateFromView:self.mapView];

        if (pinId == 1) {
            lat1 = coord.latitude;
            long1 = coord.longitude;

            MapAppAnnotation* annotation;
            annotation = [[MapAppAnnotation alloc] initWithCoordinate:coord
                                                andID:pinId];

            [mapView addAnnotation:annotation];

            MKCircle* circle = [MKCircle circleWithCenterCoordinate:coord
                                        radius:5000];
            [mapView addOverlay:circle];    
            pinId++;

        } else {
            lat2 = coord.latitude;
            long2 = coord.longitude;
            MapAppAnnotation* annotation2;
            annotation2 = [[MapAppAnnotation alloc] initWithCoordinate:coord
                                                andID:pinId];

            [mapView addAnnotation:annotation2];
        }
    } 
}

我想知道是我的错误(代码错误..)还是让我的长鼠标压力像两个不同的长压力一样的iPhone模拟器..这可能吗?

手势开始时,选择器将被调用一次,手势结束时,将再次调用选择器。 检查手势的状态并采取相应措施。

-(void)handleLongPressGesture:(UIGestureRecognizer*)sender
{
    if (sender.state != UIGestureRecognizerStateEnded) return;

    // otherwise, handle the gesture as before
}

UILongPressGestureRecognizer的类参考说:

长按手势是连续的。 当在指定时间段内(minimumPressDuration)按下了允许的手指数(numberOfTouchesRequired),并且触摸没有移动超出允许的移动范围(allowableMovement)时,手势即开始(UIGestureRecognizerStateBegan)。 每当手指移动时,手势识别器都会转换为“更改”状态,并且在任何手指抬起时手势识别器都会终止(UIGestureRecognizerStateEnded)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM