长按每次轻按会掉落 2 个引脚

发布于 2024-10-30 20:29:33 字数 1490 浏览 1 评论 0原文

我让我的应用程序通过长按来删除引脚,我只允许用户删除两个引脚,我猜它可以工作..但是每次我点击在模拟器中添加一个引脚时,它都会添加两个引脚(不仅仅是一个)..这是代码:

-(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模拟器让我的长鼠标压力像两个不同的长压力一样..这可能吗?

I got my app dropping pin by long tap, i allow users to drop only two pins and its working i guess.. but every time i tap to add a pin in the simulator it adds two pins (not only one).. here is the code:

-(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];
        }
    } 
}

I would like to know if is my fault (code error..) or is the iPhone simulator that get my long-mouse-pressure like two different long pressures.. is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走野 2024-11-06 20:29:33

当手势开始时,您的选择器将被调用一次,当手势结束时,您的选择器将被调用一次。检查手势的状态并对相关手势进行操作。

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

    // otherwise, handle the gesture as before
}

UILongPressGestureRecognizer 的类参考说:

长按手势是连续的。
手势开始
(UIGestureRecognizerStateBegan) 当
允许的手指数量
(numberOfTouchesRequired) 已
按下指定时间段
(minimumPressDuration) 和触摸
请勿超出允许范围
运动(允许的运动)。这
手势识别器转换为
每当手指移动时改变状态,
结束了
(UIGestureRecognizerStateEnded) 当
任意手指被抬起。

Your selector is being called once when the gesture begins, and again when it ends. Check the gesture's state and act on the relevant one.

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

    // otherwise, handle the gesture as before
}

The class reference for UILongPressGestureRecognizer says:

Long-press gestures are continuous.
The gesture begins
(UIGestureRecognizerStateBegan) when
the number of allowable fingers
(numberOfTouchesRequired) have been
pressed for the specified period
(minimumPressDuration) and the touches
do not move beyond the allowable range
of movement (allowableMovement). The
gesture recognizer transitions to the
Change state whenever a finger moves,
and it ends
(UIGestureRecognizerStateEnded) when
any of the fingers are lifted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文