Skip to content

Instantly share code, notes, and snippets.

@rsaunders100
Created March 2, 2012 17:38
Show Gist options
  • Save rsaunders100/1959892 to your computer and use it in GitHub Desktop.
Save rsaunders100/1959892 to your computer and use it in GitHub Desktop.
UIView+ViewExpanding.h
//
// UIView+ViewExpanding.h
// VodafoneTest
//
// Created by Robert Saunders on 02/03/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIView (ViewExpanding)
- (void) insertViewAbove:(UIView*)view;
- (void) removeView:(UIView*)view;
@end
//
// UIView+ViewExpanding.m
// VodafoneTest
//
// Created by Robert Saunders on 02/03/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "UIView+ViewExpanding.h"
@implementation UIView (ViewExpanding)
- (void) insertViewAbove:(UIView*)view {
float viewHeight = view.frame.size.height;
float oldY = self.frame.origin.y;
CGRect myFrame = self.frame;
myFrame.origin.y += viewHeight;
myFrame.size.height -= viewHeight;
CGRect newFrame = view.frame;
newFrame.origin.y = oldY;
newFrame.size.height = 0;
view.frame = newFrame;
newFrame.size.height = viewHeight;
[UIView animateWithDuration:0.8 animations:^{
self.frame = myFrame;
view.frame = newFrame;
}];
[self.superview addSubview:view];
}
- (void) removeView:(UIView*)view
{
float viewHeight = view.frame.size.height;
float oldY = view.frame.origin.y;
CGRect myFrame = self.frame;
myFrame.origin.y -= viewHeight;
myFrame.size.height += viewHeight;
CGRect newFrame = view.frame;
newFrame.origin.y = oldY;
newFrame.size.height = 0;
[UIView animateWithDuration:0.8 animations:^{
self.frame = myFrame;
view.frame = newFrame;
} completion:^(BOOL finished) {
[view removeFromSuperview];
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment