Hip*_*tes 5 iphone animation objective-c ios
ref1view.hidden = NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25f];
[ref1view setAlpha:([ref1view alpha] == 1.0f) ? 0.0f : 1.0f];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我这是如何工作的细分?特别是这一行:
[ref1view setAlpha:([ref1view alpha] == 1.0f) ? 0.0f : 1.0f];
Run Code Online (Sandbox Code Playgroud)
似乎这个函数将动画从0-1到1-0的alpha动画,我只是不理解语法.谢谢!
Jac*_*kin 13
[ref1view setAlpha:([ref1view alpha] == 1) ? 0.0f : 1.0f];:
ref1view如果它为0 则将alpha设置为1,如果为1则将其设置为0.这称为三元运算符,简写if-else.
(condition) ? conditionistrue : conditionisfalse;
Run Code Online (Sandbox Code Playgroud)