Skip to content

Instantly share code, notes, and snippets.

@mlabraca
Last active August 29, 2015 14:06
Show Gist options
  • Save mlabraca/8c296316ce13f1b3816c to your computer and use it in GitHub Desktop.
Save mlabraca/8c296316ce13f1b3816c to your computer and use it in GitHub Desktop.
animations: show and remove views with animation
//Showing view from bottom of the paren view (navigationController.view)
+ (void) showView:(UIView *)childView inParentView:(UIView *)parentView withTag:(int)tag
{
float animationTime = 0.3;
CGRect frame = CGRectMake(parentView.frame.origin.x, parentView.frame.size.height, childView.frame.size.width, childView.frame.size.height);
childView.tag = tag;
[parentView addSubview:childView];
[UIView transitionWithView:childView duration:animationTime options:UIViewAnimationOptionCurveEaseInOut animations:^{
[childView setFrame:CGRectMake(frame.origin.x, parentView.frame.size.height - childView.frame.size.height, frame.size.width, frame.size.height)];
} completion:nil];
}
//Remove view from tag from current position to bottom edges of parent view
+ (void) removeViewWithTag:(int)tag fromParentView:(UIView *)parentView
{
float animationTime = 0.3;
for (UIView *v in [parentView subviews]){
if (v.tag == tag) {
[UIView transitionWithView:v duration:animationTime options:UIViewAnimationOptionCurveEaseInOut animations:^{
[v setFrame:CGRectMake(v.frame.origin.x, parentView.frame.size.height, v.frame.size.width, v.frame.size.height)];
} completion:^(BOOL finished){
if (finished)
[v removeFromSuperview];
}];
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment