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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:24:20+00:00 2026-06-17T04:24:20+00:00

I can’t figure this out, and I don’t think this really explains it either.

  • 0

I can’t figure this out, and I don’t think this really explains it either.

I have a UILabel that can be tapped by the user to hide or show it, set up like this:

self.numberLabel.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] 
    initWithTarget:self action:@selector(hideOrShowNumber)];
[self.numberLabel addGestureRecognizer:tapGesture];

I would like to animate the hiding and showing of the label by setting the alpha value on the UILabel. However, if I set the alpha value to 0.0f, the label no longer accepts taps, so even if the user can hide the label, she can’t show it anymore!

My workaround goes like this:

When hiding the label:
– Animate the alpha value to 0.0f.
– Set the text color of the label to black (which makes it invisible because the background is black)
– Reset the alpha to 1.0f.

When showing the label:
– Set the alpha to 0.0f (because it was left at 1.0f when the label was hidden).
– Set the text color to another color than black (depending on game state).
– Animate the alpha value to 1.0f.

The code looks like this (there are some state variables included, but self.numberLabel is the reference to the UILabel):

NSTimeInterval duration = 0.6f;

if (self.numberIsVisible) {
    [UIView animateWithDuration:duration
                     animations:^{
                         self.numberLabel.alpha = 0.0f;
                     }
                     completion:^(BOOL done) {
                         self.numberLabel.textColor = [UIColor blackColor];
                         self.numberLabel.alpha = 1.0f;
                     }
    ];
    self.numberIsVisible = NO;
}
else {
    UIColor *rightColor = [UIColor whiteColor];

    if ([GameState sharedGameState].haveMatch) {
        rightColor = [UIColor colorWithRed:0.0/255.0 green:127.0/255.0 blue:255.0/255.0 alpha:1.0];
    }

    self.numberLabel.alpha = 0.0f;
    self.numberLabel.textColor = rightColor;

    [UIView animateWithDuration:duration
                     animations:^{
                         self.numberLabel.alpha = 1.0f;
                     }
    ];

    self.numberIsVisible = YES;
}

It works, but it is a little clunky.

So the question is, why does setting the transparency of the UILabel make it lose user interaction? Is this by design, and is it documented somewhere? I can’t find anything about this in the UIGestureRecognizer docs.

  • 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-17T04:24:21+00:00Added an answer on June 17, 2026 at 4:24 am

    From the official doc (Regulating Touch Event Delivery section)

    Turning off delivery of touch events. By default, a view receives
    touch events, but you can set its userInteractionEnabled property to
    NO to turn off delivery of touch events. A view also does not receive
    these events if it’s hidden or if it’s transparent
    .

    Having full transparency (alpha = 0) on a view is consider to be similar as having a view hidden so there is no reason the user interaction should he handled in that case. You could try to have nearly-transparent UILabel instead. An alpha of 0.1 seems to be the limit.

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

Sidebar

Related Questions

Can I order my users in the database, so I don't have to say
Can someone maybe tell me why this is not working? I have used echo
Can I have a project that has some parts written in c and other
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Can someone please explain how this code is working for me? I don't understand
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can anyone help me trying to find out why this doesn't work. The brushes
Can anyone explain to me why this program: for(float i = -1; i <
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't

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.