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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:49:07+00:00 2026-06-15T22:49:07+00:00

I am trying to add a UITapGestureRecognizer to a UILabel that will animate down

  • 0

I am trying to add a UITapGestureRecognizer to a UILabel that will animate down from the status bar if the user has a new announcement. I want the user to be able to click the label and goto the announcement directly. The UITapGetureRecognizer isn’t working. Here is what I am doing:

+(void)animateDown:(NSString *)title view:(UIViewController *)view color:(UIColor *)color time:(NSTimeInterval)duration
{
    view = view.navigationController.visibleViewController;
    if (currentlyDisplayed == NO) {
        if (color == nil) color = customGreen;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0 ,-40, 320, 40)];
        label.text = title;
        label.font = [UIFont fontWithName:@"STHeitiTC-Medium" size:18];
        label.backgroundColor = color;//customBlue;//[UIColor colorWithRed:0.0993145 green:0.0957361 blue:0.562879 alpha:.8f];
        label.layer.cornerRadius = 15.0f;
        [label setTextAlignment:NSTextAlignmentCenter];
        [label setMinimumFontSize:12];
        [label setAdjustsFontSizeToFitWidth:YES];
        [label sizeToFit];
        label.textColor = [UIColor whiteColor];
        if ([color isEqual:customBlue]) {
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)];
            tap.numberOfTapsRequired = 1;
            tap.numberOfTouchesRequired = 1;
            label.userInteractionEnabled = YES;
            [label addGestureRecognizer:tap];
        }
        [view.view addSubview:label];
        [view.view bringSubviewToFront:label];
        currentlyDisplayed = YES;
        [UIView animateWithDuration:.5f delay:0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveEaseIn animations:^{
            label.frame = CGRectMake(0, 0, 320, 40);
        }completion:^(BOOL finished) {
            CGFloat dur;
            if (duration == 0)  {
                dur = .5f;
            }else {
                dur = duration;
            }

            [UIView animateWithDuration:1 delay:dur options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveEaseOut animations:^{
                label.frame = CGRectMake(0,-40,320,40);
            }completion:^(BOOL finished) {
                if (finished) [label removeFromSuperview];
                currentlyDisplayed = NO;
            }];
        }]; 
    }else {
        NSMethodSignature *sig = [[self class] methodSignatureForSelector:@selector(animateDown:view:color:time:)];
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
        [invocation setSelector:@selector(animateDown:view:color:time:)];
        [invocation setTarget:self];
        [invocation setArgument:&title atIndex:2];
        [invocation setArgument:&view atIndex:3];
        [invocation setArgument:&color atIndex:4];
        [invocation setArgument:&duration atIndex:5];
        [NSTimer scheduledTimerWithTimeInterval:0.5 invocation:invocation repeats:NO];
    }
}



- (IBAction)onTap:(UIPanGestureRecognizer *)recognizer {
    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"announcementTapped" object:nil]];
    NSLog(@"tapped");
}

The onTap method is never called….It goes into the if statement..See image:
enter image description here

  • 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-15T22:49:08+00:00Added an answer on June 15, 2026 at 10:49 pm

    It’s failing to recognize the touch because it’s being tapped in a UIView animation block.

    Try adding UIViewAnimationOptionAllowUserInteraction to the options parameter when animating.


    EDIT

    The problem is that the actual position of the UIView‘s layer is at the final destination. What you want to do is check if its presentationLayer is at the position which was tapped.

    To solve this, you could add the gesture to the main view instead of the actual label, and on tap check if the touch location is within the label’s presentationLayer:

    - (IBAction)onTap:(UITapGestureRecognizer *)tapGestureRecognizer {
        CGPoint point = [tapGestureRecognizer locationInView:tapGestureRecognizer.view];
        BOOL labelTapped = [self.label.layer.presentationLayer hitTest:point] != nil;
        if (labelTapped) {
            // do something
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm new to django and im trying add a user using django admin page.
I'm trying add some implicit rules in CMake that will generate direct dependencies (like
Trying to add a view that combines data from two tables with a right
I'm trying to add a UITapGestureRecognizer to my app so I can detect and
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add a custom header item to a Lotus Notes email item, from
Trying to add text to QGraphicsView: Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this);
I am trying add two columns in a text file that are seperated by
im trying to add table data from mysql to csv and output them to
Trying to add handling for when the selected item changes in a drop-down. However,

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.