Last active
August 29, 2015 14:04
-
-
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
This file contains 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
- (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