views:

73

answers:

2
    ref1view.hidden = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25f];
[ref1view setAlpha:([ref1view alpha] == 1) ? 0.0f : 1.0f];
[UIView commitAnimations];

Can anyone please give me a breakdown of how this works.. Specifically the:

    [ref1view setAlpha:([ref1view alpha] == 1) ? 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!

+7  A: 

[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;
Jacob Relkin
Yep, ternary op.
Kevin
+2  A: 

its a ternary operator...would be the same as

if(ref1view alpha == 1)
{
[ref1view setAlpha:0.0f];
}
else
{
[ref1view setAlpha:1.0f];
}
Jesse Naugher