Observe this code:
- (void)hideRectangleWithAnimation:(BOOL)animate completion:(void (^)(void))completionBlock
{
if (animate)
{
// Hide rectangle
[UIView animateWithDuration:0.3 animations:^{ rect.alpha = 0; } completion:^(BOOL finished){
completionBlock();
}
}
else
{
rect.alpha = 0;
}
}
Is there a way to not repeat the property change: rect.alpha = 0; twice?
This line of code is currently trivial but there could be a more complex case where multiple stuff are happening.
I think I just found the answer. I can put
rect.alpha = 0;in a block variable and use that instead.