@implementation UIViewController(AnimationFashion)
#pragma mark
#pragma mark implementation
//regard the control as child view of self by default.
- (void) scrollViewIfControlCoveredByKeyboard:(UIControl *)control hasStatusBar:(BOOL)hasStatusBar hasNavigationBar:(BOOL)hasNavBar{
CGFloat keyboardHeight = 216.0f;
CGFloat navBarHeight = 44.0f;
CGFloat statusBarHeight = 20.0f;
CGFloat screenHeight = 480.0f;
ViewOriginFrame = self.view.frame;
CGFloat controlYRelativeToScreen = control.frame.origin.y + self.view.frame.origin.y + control.frame.size.height;
if (hasStatusBar) {
controlYRelativeToScreen += statusBarHeight;
}
if (hasNavBar) {
controlYRelativeToScreen += navBarHeight;
}
CGFloat invisiblePixels = keyboardHeight - (screenHeight - controlYRelativeToScreen);
if (invisiblePixels > 0) {
//in this case, the control is covered by keyboard, so scroll view to make it visible.
[UIView beginAnimations:@"scrollView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.275f];
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - invisiblePixels, self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
}
- (void) restoreViewPosition{
[UIView beginAnimations:@"restoreViewPosition" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.200f];
self.view.frame = ViewOriginFrame;
[UIView commitAnimations];
}
- (void) didPopUpView:(id)sender{
if(self.navigationController != nil){
[self.navigationController popViewControllerAnimated:YES];
}
}
@end