Skip to content

Instantly share code, notes, and snippets.

@SlaunchaMan
Last active August 29, 2015 13:57
Show Gist options
  • Save SlaunchaMan/9515841 to your computer and use it in GitHub Desktop.
Save SlaunchaMan/9515841 to your computer and use it in GitHub Desktop.
Why the heck doesn’t this work?
- (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();
}
}
@SlaunchaMan
Copy link
Author

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?

@SlaunchaMan
Copy link
Author

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