Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7879915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:00:52+00:00 2026-06-03T04:00:52+00:00

I need to recognize in which direction performed swipe and to know which object

  • 0

I need to recognize in which direction performed swipe and to know which object on my view has sent it. I’ve found workaround for now but it looks complicated and monstrous so I doubt is there any simplest solution?
My workaround in few words:

  1. I attached recognizers to every UIButton objects on my view.
  2. There is indicator that shows which button was tapped during performing swipe
  3. I have to check this indicator and swipe direction for making right decision, which object and in which direction it should be moved.

Thank you in advise.

@synthesize swipeDirection;   //label which shows swipe direction
@synthesize buttonNumber;       //label which shows number of button which being tapped

    - (void)viewDidLoad
    {
        UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];     //creating button       
        [button setTitle:@"test1" forState:UIControlStateNormal];                        
        button.frame = CGRectMake(100, 100, 100, 100);
        [button addTarget:self                                          //adding selector which will update indicator which button been tapped, there isn't way to make swipe without tap button
                   action:@selector(updateButtonNumber:)
         forControlEvents:UIControlEventTouchDown];
        [button setTag:1];
        [self.view addSubview:button];              //add button to view
        [self beginListenToSwipes:button];          //send button to method which will add UISwipeGestureRecognizer for 4 directions

        /*same task for second button*/
        UIButton* button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];            
        [button1 setTitle:@"test2" forState:UIControlStateNormal];                        
        button1.frame = CGRectMake(200, 200, 100, 100);
        [button1 addTarget:self                         
                   action:@selector(updateButtonNumber:)
         forControlEvents:UIControlEventTouchDown];
        [button1 setTag:2];
        [self.view addSubview:button1];
        [self beginListenToSwipes:button1];

    }

    /*every time when we tap button (begin swipe this method is called and buttonNumber always points to current button*/
    -(void)updateButtonNumber:(UIButton*)sender
    {
        self.buttonNumber.text = [NSString stringWithFormat:@"%d",sender.tag];
    }

    /*method receives UIButton and add to it recognizers*/
    - (void) beginListenToSwipes:(UIButton*)sender
    {
        UISwipeGestureRecognizer *recognizer;
        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
        [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
        [sender addGestureRecognizer:recognizer];

        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
        [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
        [sender addGestureRecognizer:recognizer];

        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
        [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
        [sender addGestureRecognizer:recognizer];

        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
        [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
        [sender addGestureRecognizer:recognizer];
    }

    /*method which called when swipe performed and shows in which direction it was performed*/
    -(void)handleSwipe:(UISwipeGestureRecognizer *)recognizer 
    {
        int i = recognizer.direction;
        self.swipeDirection.text = [NSString stringWithFormat:@"%d",i];
    }

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:00:53+00:00Added an answer on June 3, 2026 at 4:00 am

    My idea would be,

    1. Register for touchUpoutside event for UIButton.
    2. When you move your finger out of the button it will be fired.
    3. Find the touch point from touchesEnded method and store in a class level variable.
    4. Compare the button frame and touched point in the touchupoutside method to find the direction of movement.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to know, how to recognize, which button is pressed. Like if i
I asked a similar question yesterday, but recognize that i need to rephase it
I need to complete the demo project which aims to recognize teeth on the
If I ONLY need older browsers to recognize HTML5 tags, which should I use,
I need the iPhone to recognize the current time (which I can do fine
I need to read one C++ head file which has some Chinese and was
I need to recognize some elements drawn with user's finger on device's screen. For
I am working on a on-screen keyboard for Android, and I need to recognize
I'm curious, why does sed need 3 \ just to recognize one? I'd understand
I need to recognize the speech from a set of WAV files that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.