ref1view.hidden = NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25f];
[ref1view setAlpha:([ref1view alpha] == 1.0f) ? 0.0f : 1.0f];
[UIView commitAnimations];
Can anyone please give me a breakdown of how this works? Specifically this line:
[ref1view setAlpha:([ref1view alpha] == 1.0f) ? 0.0f : 1.0f];
It seems that this function will animate the alpha from 0-1 and back from 1-0 and I just don't understand the syntax. Thanks!
[ref1view setAlpha:([ref1view alpha] == 1) ? 0.0f : 1.0f];
:
Sets the alpha of ref1view
to be 1 if it's 0, or 0 if it's 1. This is called the ternary operator, a shorthand if-else
.
(condition) ? conditionistrue : conditionisfalse;
its a ternary operator...would be the same as
if(ref1view alpha == 1)
{
[ref1view setAlpha:0.0f];
}
else
{
[ref1view setAlpha:1.0f];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With