Created
March 2, 2012 17:38
-
-
Save rsaunders100/1959892 to your computer and use it in GitHub Desktop.
UIView+ViewExpanding.h
This file contains hidden or 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
// | |
// 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 |
This file contains hidden or 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
// | |
// 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