IOS `UIView` stops responding to gesture recognizer when its alpha is 0?

I have a UIView configured, its behavior looks like this: after I loaded it from nib and added it to my view hierarchy, it is almost transparent at first (alpha = 0,1), when I click it, it becomes opaque (alpha = 1.0), after a while it becomes almost transparent (alpha = 0.1).

The code in a custom form looks like this: it works the same way as described above:

 - (void)awakeFromNib { [self setup]; } - (void)setup { self.alpha = 0.1f; [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]]; } - (void)tapped:(UITapGestureRecognizer *)tapRecognizer { if (self.alpha == 1.0) { [self hideSelf]; } else { [UIView animateWithDuration:0.5 animations:^{ self.alpha = 1.0f; } completion:^(BOOL finished) { [self.timer invalidate]; self.timer = nil; self.timer = [NSTimer timerWithTimeInterval:3 target:self selector:@selector(hideSelf) userInfo:nil repeats:NO]; [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode]; }]; } } - (void)hideSelf { [UIView animateWithDuration:0.5 animations:^{ self.alpha = 0.1f; } completion:^(BOOL finished) { [self.timer invalidate]; self.timer = nil; }]; } 

But I do not want "almost transparent (alpha = 0,1)", I want "transparent (alpha = 0.0)". So I just change "0.1" to "0.0" in my code. But when I click on the view, it does not even call the tapped: method. Why is this so? How can I make it work?

+7
ios objective-c transparency
source share
2 answers

It works this way, if you change the alpha representation to zero, it will stop receiving touch events.

You could change the background color of the view to transparent, instead of changing the alpha view, so your view will not be visible and you will receive events.

+8
source share

fully transparent means hidden right, and does not make it equal to 0.0, makes UIview hidden and places the button with a clear Uicolor color at the same point and transfers control to it.

0
source share

All Articles