Last active
August 29, 2015 13:57
-
-
Save SlaunchaMan/9515841 to your computer and use it in GitHub Desktop.
Why the heck doesn’t this work?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)doTheThingAnimated:(BOOL)animated | |
{ | |
CGFloat buttonAlpha = 1.0f; | |
CGFloat leftLabelAlpha = 1.0f; | |
CGFloat rightLabelAlpha = 1.0f; | |
if ([BUSINESS LOGIC]) { | |
buttonAlpha = 0.0f; | |
rightLabelAlpha = 0.0f; | |
} | |
else if ([BUSINESS LOGIC]) { | |
buttonAlpha = 0.0f; | |
leftLabelAlpha = 0.0f; | |
} | |
void (^animations)(void) = ^{ | |
self.leftSideButton.imageView.alpha = buttonAlpha; | |
self.leftSideLabel.alpha = leftLabelAlpha; | |
self.rightSideButton.imageView.alpha = buttonAlpha; | |
self.rightSideLabel.alpha = rightLabelAlpha; | |
}; | |
if (animated) { | |
[UIView animateWithDuration:kSideSelectionAnimationDuration | |
delay:kSideSelectionAnimationDelay | |
options:kSideSelectionAnimationOptions | |
animations:animations | |
completion:NULL]; | |
} | |
else { | |
animations(); | |
} | |
} |
After further review: calling this method from the action on the left or right button prevents the touched button’s image view from animating, but calling it using dispatch_async()
on the main queue works. That’s ugly, but it works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When this method fires—as a result of tapping the left or right button—the image view of the tapped button doesn’t get its alpha animated, but the image view of the other button does. Am I crazy?