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

  • Home
  • SEARCH
  • 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 3977298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:54:25+00:00 2026-05-20T04:54:25+00:00

I have a UILongPressGestureRecognizer added to a UIButton. When I press the UIButton it

  • 0

I have a UILongPressGestureRecognizer added to a UIButton. When I press the UIButton it gets highlighted as expected. However, when the UILongPressGestureRecognizer selector gets called the highlighting gets turned off.

    UILongPressGestureRecognizer *longpressGesture = 
     [[UILongPressGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(longPressHandler:)];
    longpressGesture.minimumPressDuration = 5;
    [longpressGesture setDelegate:self];
    [self.myUIButton addGestureRecognizer:longpressGesture];
    [longpressGesture release];

    - (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer {
    NSLog(@"longPressHandler");
}

In the above example, the selector gets called after 5 seconds of holding down the button. The button is highlighted prior to the selector being called, but then gets unhighlighted when the selector is called, even though I am still pressing the button.

Can anyone explain why this happens, and how it can be prevented? I would like the button to remain highlighted the entire time while pressed down. Thanks.

  • 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-05-20T04:54:26+00:00Added an answer on May 20, 2026 at 4:54 am

    After further research, I discovered that this is due to the default behavior of Gesture Recognizers, which cancel touches in the hierarchy once they recognize a gesture. So, once the Gesture Recognizer recognizes a gesture, it cancels the touch to the UI Button, which then gets unhighlighted, since it no longer has a touch event.

    This behavior can be changed using the cancelsTouchesInView property

    longpressGesture.cancelsTouchesInView = NO;
    

    Setting this to NO will pass the touch through to the responder chain.

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

Sidebar

Related Questions

I have my table view and the cells within it have the UILongPressGestureRecognizer added
CODE I have some code that adds a UILongPressGestureRecognizer gesture recognizer called _recognizer to
UILongPressGestureRecognizer *longPressOnUndoGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressOnUndoGesture:)]; [longPressOnUndoGesture setMinimumPressDuration:2.0]; [longPressOnUndoGesture release]; i have the
I have a UIButton with 2 functions: tap, and long press. A bit like
Possible Duplicate: UIButton long press with finger stationary I have created 100 buttons from
guys, I have added two UILongPressGestureRecognizer. What I want is when two buttons are
i have 2 uibutton and 1 label and longpressgesture is bounded to these control.
In a tableview I have on every cell a UILongPressGestureRecognizer which I add like
Have deployed numerous report parts which reference the same view however one of them
In cellForRowAtIndexPath: method I have implemented gesture recognizer for long press, -(UITableViewCell *)tableView:(UITableView *)tableView

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.