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?
ios objective-c transparency
axl411
source share