@implementation UITableView(AnimationFashion)
- (void) scrollViewIfControlCoveredByKeyboard:(UIControl *)control atIndexPath:(NSIndexPath *)indexPath hasStatusBar:(BOOL)hasStatusBar hasNavigationBar:(BOOL)hasNavBar{
CGFloat keyboardHeight = 216.0f;
CGFloat navBarHeight = 44.0f;
CGFloat statusBarHeight = 20.0f;
CGFloat screenHeight = 480.0f;
ViewOriginFrame = self.frame;
CGFloat controlYRelativeToScreen = (((CGRect)[self rectForRowAtIndexPath:indexPath]).origin.y + control.frame.origin.y) + self.frame.origin.y + control.frame.size.height;
NSLog(@"Cell Y %f",((CGRect)[self rectForRowAtIndexPath:indexPath]).origin.y);
NSLog(@"Self Y %f",control.frame.origin.y);
NSLog(@"Tbl Y %f",self.frame.origin.y);
NSLog(@"Self H %f",control.frame.size.height);
NSLog(@"All H %f",controlYRelativeToScreen);
if (hasStatusBar) {
controlYRelativeToScreen += statusBarHeight;
}
if (hasNavBar) {
controlYRelativeToScreen += navBarHeight;
}
CGFloat invisiblePixels = keyboardHeight - (screenHeight - controlYRelativeToScreen) - self.bounds.origin.y;//
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.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y - invisiblePixels, self.frame.size.width, self.frame.size.height);
[UIView commitAnimations];
}
}
- (void) restoreViewPosition{
[UIView beginAnimations:@"restoreViewPosition" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.200f];
self.frame = ViewOriginFrame;
[UIView commitAnimations];
}
@end