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 9155197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:00+00:00 2026-06-17T12:33:00+00:00

How can I send a UILongPressGesture message to an object? I know how to

  • 0

How can I send a UILongPressGesture message to an object?

I know how to send touches, but not gestures. For example, if I wanted to send a touch I could use:

[button sendActionsForControlEvents: UIControlEventTouchUpInside];

and the button would receive a “touch up inside”. I need to do the same thing with a long press gesture.

Think automated UI testing. Calling a selector associated with the gesture wouldn’t meaningfully test anything.

  • 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-17T12:33:01+00:00Added an answer on June 17, 2026 at 12:33 pm

    Import <UIKit/UIGestureRecognizerSubclass.h> and manually set the state property as appropriate to the sequence of states you need to simulate. This will cause the added target/action pairs to be called. After each time manually setting the state, you must let the run loop run in order for the messages to be dispatched.

    For the UILongPressGestureRecognizer, to get the correct sequence of states as is found in an actual, ‘touch, hold, drag, release’ sequence of gestures, I wrote the following code in a UIViewController subclass inside viewDidLoad.:

    UILongPressGestureRecognizer *r = [[UILongPressGestureRecognizer alloc] init];
    [self.view addGestureRecognizer:r];
    [r addTarget:self action:@selector(recognize:)];
    r.state = UIGestureRecognizerStateBegan;
    [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
    r.state = UIGestureRecognizerStateChanged;
    [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
    r.state = UIGestureRecognizerStateEnded;
    [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
    [r reset];
    

    I imagine this would be risky in production code (you may wish afterwards to call reset but I found no difference between doing so or not in my testing), but if your use case is automated testing to verify that the targets and actions have been set correctly this may meet your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know we can send a message from within an iPhone app, but I
Using outlook I can send emails with images inserted into message body(not as attachment).
From what I know you can send JSON data via POST, but should PUT
I know you can send emails with PHP but, can you receive emails through
I know I can send a custom field using IPN with $_POST['custom'] But can
To send string I use StreamWriter but how I can send Hashtable ? Or
i know that we can send variables in url by this syntax: http://www.example.com/index.php?a=1&b=2 and
I know that soap can send XML over http, is there any way to
Using cURL I can send a GET request with a body. Example: curl -i
client1 can send txt message to client2 using connection.getChatManager().createChat(to, this).sendMessage(message); How to send other

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.