Skip to content

Instantly share code, notes, and snippets.

@StuartFarmer
Last active August 29, 2015 14:04
Show Gist options
  • Save StuartFarmer/a7bef650653911a76bfa to your computer and use it in GitHub Desktop.
Save StuartFarmer/a7bef650653911a76bfa to your computer and use it in GitHub Desktop.
Basic IBAction code to toggle fades in and out with animation for controls in UIView
- (IBAction)showToolbarButtonPressed:(id)sender {
// Set up conditional to setup toggle feature.
// This conditional checks if the toolbar is invisible, and if it is, it animates the opacity to 100%, otherwise, it assumes the toolbar is visible, and animates the opacity to 0%. Code can check any other conditionals, ie. self.toolbar.isHidden == YES, etc.
if (self.toolbar.alpha == 0.0f) {
// Disable button
[self.showToolbarButton setEnabled:NO];
// Fade toolbar in w/ Animation
[UIView animateWithDuration:2.0f
delay:0.5f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.toolbar setAlpha:1.0f];
}
completion:^(BOOL finished){
// On completion, reenable button
[self.showToolbarButton setEnabled:YES];
}];
}
else {
// Disable button
[self.showToolbarButton setEnabled:NO];
// Fade toolbar out w/ Animation
[UIView animateWithDuration:2.0f
delay:0.5f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.toolbar setAlpha:0.0f];
}
completion:^(BOOL finished){
// On completion, reenable button
[self.showToolbarButton setEnabled:YES];
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment