Skip to content

Instantly share code, notes, and snippets.

@bjhomer
Created March 21, 2012 21:04
Show Gist options
  • Save bjhomer/2152823 to your computer and use it in GitHub Desktop.
Save bjhomer/2152823 to your computer and use it in GitHub Desktop.
A useful pattern for UIKit's -setFoo:animated: methods
- (void)setFoo:(BOOL)foo animated:(BOOL)animated {
[super setFoo:foo animated:animated];
dispatch_block_t changes = ^{
if (foo) {
someView.alpha = 1.0;
}
else {
someView.alpha = 0.0;
}
};
if (animated) {
[UIView animateWithDuration:0.2 animations:changes];
}
else {
changes();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment