Swipe 方法被调用两次

发布于 2024-12-02 21:30:48 字数 725 浏览 1 评论 0原文

我必须在视图控制器中使用滑动功能。 因此,每当我滑动时,我的滑动方法都会被调用两次,并且我在 (swipe:) 方法中编写的 NSlog 会显示内容两次。

这是我使用过的代码。

UIView *swipeView=[[UIView alloc]initWithFrame:CGRectMake(405, 420, 265, 35)];
    swipeView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:swipeView];
    UISwipeGestureRecognizer *gesture;
    gesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
    [gesture setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [swipeView addGestureRecognizer:gesture];
    [gesture release];
    [swipeView release];


 -(void)swipe:(UISwipeGestureRecognizer *)recognizer {
    NSLog(@"Swipe received.");
    NSLog(@"HIJ");
}

请告诉我只调用一次需要做什么。

I have to use swipe functionality in my view controller.
so, whenever Iam swiping, my swipe method is getting called twice and the NSlogs which I Wrote inside the (swipe:) method is displaying the content two times.

Here is the code which i have used.

UIView *swipeView=[[UIView alloc]initWithFrame:CGRectMake(405, 420, 265, 35)];
    swipeView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:swipeView];
    UISwipeGestureRecognizer *gesture;
    gesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
    [gesture setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [swipeView addGestureRecognizer:gesture];
    [gesture release];
    [swipeView release];


 -(void)swipe:(UISwipeGestureRecognizer *)recognizer {
    NSLog(@"Swipe received.");
    NSLog(@"HIJ");
}

please tell me what i have to do for calling it only one time.

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

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

发布评论

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

评论(2

梦萦几度 2024-12-09 21:30:48

这就是应该发生的事情。您需要查看 state 属性,您可以在其中找到类似的内容UIGestureRecognizerStateBeganUIGestureRecognizerStateEnded

That's what's supposed to happen. You need to look at the state property where you'll find things like UIGestureRecognizerStateBegan and UIGestureRecognizerStateEnded.

苏辞 2024-12-09 21:30:48

试试这个,识别器有各种状态,例如

UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded




-(void)swipe:(UISwipeGestureRecognizer *)recognizer {


    if (recognizer.state == UIGestureRecognizerStateEnded) {


        NSLog(@"Swipe received.");
        NSLog(@"HIJ");

    }
}

Try this, recognizer has various state like

UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded




-(void)swipe:(UISwipeGestureRecognizer *)recognizer {


    if (recognizer.state == UIGestureRecognizerStateEnded) {


        NSLog(@"Swipe received.");
        NSLog(@"HIJ");

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