UIButton attenuation when touched

I have selected state and normal state for UIButton, which are UIImages. When the button is pressed, I would like it to fall into the selected state, and then plunge into the normal state for one second. I set the following animation when I pressed the UIButton * btn button, but it again switches back to the unselected state. How do I achieve this?

[btn setSelected:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];
[btn setSelected:NO];
[UIView commitAnimations];

Greetings

Nick

+3
source share
1 answer

selected , ( ). , btn UIImageView โ€‹โ€‹ . :

- (void) tapButton:(UIButton *)btn {
    btn.alpha = 0;
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:[UIApplication sharedApplication]];
    [UIView setAnimationDidStopSelector:@selector(endIgnoringInteractionEvents)];
    btn.alpha = 1;
    [UIView commitAnimations];
}

. begin/endIgnoringInteractionEvents, , . , begin/end [UIView setAnimationBeginsFromCurrentState];

+12

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


All Articles