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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:52:58+00:00 2026-06-12T08:52:58+00:00

I create a simple view (black square) with long press gesture and drag it

  • 0

I create a simple view (black square) with long press gesture and drag it on the screen (UIGestureRecognizerStateChanged) until i catch UIGestureRecognizerStateEnded. OK, this works well. Now I want to be able to start recognizing additional gesture (UISwipeGestureRecognizer) for this black square view. The algorithm is simple:

  1. Create black square with long press
  2. Finger stays on screen
  3. Drag square view (setCenter:)
  4. Swipe and recognize UISwipeGestureRecognizer

The problem is that I cant recognize swipe while the long press gesture is not finished (UIGestureRecognizerStateEnded)

#pragma mark - View lifecycle

- (void)loadView {
    [super loadView];

    // Long press
    self.longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)];
    [self.longPressGestureRecognizer setDelegate:self];
    [self.view addGestureRecognizer:self.longPressGestureRecognizer];

    // Swipe
    self.swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)];
    [self.swipeGestureRecognizer setDelegate:self];
    [self.swipeGestureRecognizer setEnabled:NO];
    [self.view addGestureRecognizer:self.swipeGestureRecognizer];
}

#pragma mark - Gesture recognizer

- (void)gestureAction:(UIGestureRecognizer *)recognizer {

    // Swipe
    if ([recognizer isKindOfClass:NSClassFromString(@"UISwipeGestureRecognizer")]) {
        NSLog(@"swipeGestureRecognizer handled!!");
    }

    // Long press
    if ([recognizer isKindOfClass:NSClassFromString(@"UILongPressGestureRecognizer")]) {
        if (recognizer.state == UIGestureRecognizerStateBegan) {
            self.activeView = [[ItemView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
            [self.activeView setBackgroundColor:[UIColor blackColor]];
            self.activeView.center = [recognizer locationInView:self.view];
            [self.view addSubview:self.activeView];
        }
        else if (recognizer.state == UIGestureRecognizerStateChanged) {
            if (![self.swipeGestureRecognizer isEnabled]) {
                [self.swipeGestureRecognizer setEnabled:YES];
                NSLog(@"swipeGestureRecognizer enabled");
            }
            self.activeView.center = [recognizer locationInView:self.view];
        }
        else if (recognizer.state == UIGestureRecognizerStateEnded) {
            [self.swipeGestureRecognizer setEnabled:NO];
            NSLog(@"swipeGestureRecognizer disabled");
            [self.activeView removeFromSuperview];
            self.activeView = nil;
        }
    }
}

#pragma mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    return YES;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    return YES;
}

P.S. I want the behavior exactly as in native Calendar app when you are creating an event on the day canvas with long press. If you swipe an object (before you end long press gesture) it smoothly disappears.

  • 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-12T08:53:00+00:00Added an answer on June 12, 2026 at 8:53 am

    For multiple gestures to recognized simultaneosly, you need to use the following delegate method from UiGestureRecognizer Protocol,

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
    

    Here is the LINK to the documentation.

    EDIT

    So I tried doing the same thing and, Yes even in my case the swipe was not recognized until long press is over..! So fi you want to move the view around, THen use PanGesture instead of swipe gesture..! It will work I just tried..:)

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

Sidebar

Related Questions

I'm starting out with backbone and I'm trying to create a simple view that
I want to create simple app able to edit images. Main view of app
I'm trying to create a simple view helper but as soon as I try
I am trying to create a resize toggle animation on this simple custom TUIScrollView
I have follow a sample code, for create a simple image view zoom/pan page,
I have created a simple view consisting of 3 tables in SQL. By right
I have a simple UIViewController whose view is created via a Nib. Here's the
I created a custom view that uses Json.Simple to serialize the model and write
I need to create a custom view, which extends RelativeLayout and simply needs to
I have created programme in which we navigate from table view to a simple

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.