How to make a button disappear after clicking on iOS / xcode?

I want the button to disappear after clicking. I know I can use

_myButon.hidden = TRUE; 

... completely hide the button, but it seems sharp and sharp. I also know that I could consistently reduce alpha or something like that, but I did not know how this would happen automatically in a short amount of time.

Can someone please give me a hint how to turn off a button after pressing it using the simplest means? I want the effect to look like a simple β€œfade-out” from a PowerPoint presentation or something else :)

Thanks!

+4
source share
4 answers
 [UIView animateWithDuration:0.5 animations:^{ _myButton.alpha = 0; }]; 
+8
source

Instead of deleting the button, just hide it. Taking into account all the offers, you get:

 [UIView animateWithDuration:0.5 animations:^{ _myButton.alpha = 0; } completion:^(BOOL finished){ _myButton.hidden = YES; } ]; 
+4
source
 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; _myButton.alpha = 0.0f; [UIView commitAnimations]; 

as an alternative

 [UIView animateWithDuration:1.0 animations:^{ _myButton.alpha = 0.0f; }]; 
+2
source

Simply removing the alpha will not force your button to be completely removed from your view. To the user, it will be like disappearing, but still there. They potentially could still accidentally click on it, not knowing. So what you can do is make a timer to remove it from the view after it has disappeared.

 ... //alpha animation //remove from view timer1 = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(hideMyButton) userInfo:nil repeats:NO]; } -(IBAction) hideMyButton { [_myButon removeFromSuperview]; } 
+1
source

Source: https://habr.com/ru/post/1489383/


All Articles