Permalink
Browse files

Remove the resizing for keyboard from DCTTableViewController

  • Loading branch information...
1 parent 9ca7487 commit f1b565d3be101d54b94d9b8addc982bff88e90b5 @danielctull committed Sep 17, 2011
Showing with 74 additions and 72 deletions.
  1. +0 −2 DCTTableViewController.m
  2. +2 −3 DCTViewController.h
  3. +71 −2 DCTViewController.m
  4. +1 −65 UIViewController+DCTViewController.m
@@ -47,8 +47,6 @@ @implementation DCTTableViewController {
}
@synthesize tableViewDataSource;
-@synthesize resizeViewToFitKeyboard;
-@synthesize resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard;
#pragma mark - NSObject
View
@@ -41,9 +41,6 @@
@protocol DCTViewController <NSObject>
-@property (nonatomic, assign) BOOL resizeViewToFitKeyboard;
-@property (nonatomic, assign) BOOL resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard;
-
- (void)keyboardWillShowNotification:(NSNotification *)notification;
- (void)keyboardDidShowNotification:(NSNotification *)notification;
- (void)keyboardWillHideNotification:(NSNotification *)notification;
@@ -62,4 +59,6 @@
/** Subclass of UIViewController.
*/
@interface DCTViewController : UIViewController<DCTViewController>
+@property (nonatomic, assign) BOOL resizeViewToFitKeyboard;
+@property (nonatomic, assign) BOOL resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard;
@end
View
@@ -40,6 +40,10 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#import "UINib+DCTExtensions.h"
#import "UIViewController+DCTViewController.h"
+@interface DCTViewController ()
+- (void)dctInternal_keyboardWillHide:(BOOL)hidden withNotification:(NSNotification *)notification;
+@end
+
@implementation DCTViewController
@synthesize resizeViewToFitKeyboard;
@@ -107,9 +111,74 @@ - (IBAction)dismissModalViewController:(id)sender {
- (void)sharedInit {}
- (void)loadTitle {}
-- (void)keyboardWillShowNotification:(NSNotification *)notification {}
+- (void)keyboardWillShowNotification:(NSNotification *)notification {
+ if (self.resizeViewToFitKeyboard)
+ [self dctInternal_keyboardWillHide:NO withNotification:notification];
+}
- (void)keyboardDidShowNotification:(NSNotification *)notification {}
-- (void)keyboardWillHideNotification:(NSNotification *)notification {}
+
+- (void)keyboardWillHideNotification:(NSNotification *)notification {
+ if (self.resizeViewToFitKeyboard)
+ [self dctInternal_keyboardWillHide:YES withNotification:notification];
+}
+
- (void)keyboardDidHideNotification:(NSNotification *)notification {}
+- (void)dctInternal_keyboardWillHide:(BOOL)hidden withNotification:(NSNotification *)notification {
+
+ UIView *view = self.view;
+
+ NSDictionary *userInfo = [notification userInfo];
+
+ CGRect keyboardEndRect, keyboardBeginRect;
+ [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndRect];
+ [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&keyboardBeginRect];
+
+ if (keyboardEndRect.origin.y == keyboardBeginRect.origin.y) return;
+
+ UIWindow *window = view.window;
+ CGRect endRect = [window convertRect:keyboardEndRect toView:view];
+
+ CGRect originalRect;
+
+ if (!hidden) originalRect = view.frame;
+
+ if (self.resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard) {
+
+ CGRect beginRect = [window convertRect:keyboardBeginRect toView:view];
+
+ [UIView animateWithDuration:0.0f animations:^(void) {
+ view.frame = CGRectMake(originalRect.origin.x,
+ originalRect.origin.y,
+ originalRect.size.width,
+ beginRect.origin.y);
+ }];
+ }
+
+ UIViewAnimationCurve curve;
+ [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&curve];
+ UIViewAnimationOptions animationOptions = [UIView dct_animationOptionCurveForAnimationCurve:curve];
+
+ double duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
+
+ [UIView animateWithDuration:duration
+ delay:0.0f
+ options:animationOptions
+ animations:^(void) {
+
+ if (hidden && !self.resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard)
+ view.frame = originalRect;
+ else
+ view.frame = CGRectMake(originalRect.origin.x,
+ originalRect.origin.y,
+ originalRect.size.width,
+ endRect.origin.y);
+
+ } completion:^(BOOL finished) {
+
+ if (hidden && self.resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard)
+ view.frame = originalRect;
+ }];
+}
+
@end
@@ -49,8 +49,6 @@ - (void)dctInternal_keyboardDidShowNotification:(NSNotification *)notification;
- (void)dctInternal_keyboardWillHideNotification:(NSNotification *)notification;
- (void)dctInternal_keyboardDidHideNotification:(NSNotification *)notification;
-- (void)dctInternal_keyboardWillHide:(BOOL)hidden withNotification:(NSNotification *)notification;
-
- (void)dctInternal_safeLoadNibNamed:(NSString *)nibName inBundle:(NSBundle *)bundle;
@property (nonatomic, readonly) UIViewController<DCTViewController> *dctViewController;
@@ -105,13 +103,10 @@ - (void)dct_dismissModalViewController:(id)sender {
- (void)dct_sharedInit {
[self title];
- self.dctViewController.resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard = YES;
[self.dctViewController sharedInit];
}
-- (void)dctInternal_keyboardWillShowNotification:(NSNotification *)notification {
- if (self.dctViewController.resizeViewToFitKeyboard) [self dctInternal_keyboardWillHide:NO withNotification:notification];
-
+- (void)dctInternal_keyboardWillShowNotification:(NSNotification *)notification {
[self.dctViewController keyboardWillShowNotification:notification];
}
@@ -120,8 +115,6 @@ - (void)dctInternal_keyboardDidShowNotification:(NSNotification *)notification {
}
- (void)dctInternal_keyboardWillHideNotification:(NSNotification *)notification {
- if (self.dctViewController.resizeViewToFitKeyboard) [self dctInternal_keyboardWillHide:YES withNotification:notification];
-
[self.dctViewController keyboardWillHideNotification:notification];
}
@@ -145,63 +138,6 @@ - (void)dctInternal_removeKeyboardObservers {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
}
-- (void)dctInternal_keyboardWillHide:(BOOL)hidden withNotification:(NSNotification *)notification {
-
- UIView *view = self.view;
-
- NSDictionary *userInfo = [notification userInfo];
-
- CGRect keyboardEndRect, keyboardBeginRect;
- [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndRect];
- [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&keyboardBeginRect];
-
- if (keyboardEndRect.origin.y == keyboardBeginRect.origin.y) return;
-
- UIWindow *window = view.window;
- CGRect endRect = [window convertRect:keyboardEndRect toView:view];
-
- CGRect originalRect;
-
- if (!hidden) originalRect = view.frame;
-
- if (self.dctViewController.resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard) {
-
- CGRect beginRect = [window convertRect:keyboardBeginRect toView:view];
-
- [UIView animateWithDuration:0.0f animations:^(void) {
- view.frame = CGRectMake(originalRect.origin.x,
- originalRect.origin.y,
- originalRect.size.width,
- beginRect.origin.y);
- }];
- }
-
- UIViewAnimationCurve curve;
- [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&curve];
- UIViewAnimationOptions animationOptions = [UIView dct_animationOptionCurveForAnimationCurve:curve];
-
- double duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
-
- [UIView animateWithDuration:duration
- delay:0.0f
- options:animationOptions
- animations:^(void) {
-
- if (hidden && !self.dctViewController.resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard)
- view.frame = originalRect;
- else
- view.frame = CGRectMake(originalRect.origin.x,
- originalRect.origin.y,
- originalRect.size.width,
- endRect.origin.y);
-
- } completion:^(BOOL finished) {
-
- if (hidden && self.dctViewController.resizeViewToBottomEdgeOfScreenBeforeResizingForKeyboard)
- view.frame = originalRect;
- }];
-}
-
- (void)dctInternal_safeLoadNibNamed:(NSString *)nibName inBundle:(NSBundle *)bundle {
if ([UINib dct_nibExistsWithNibName:nibName bundle:bundle])

0 comments on commit f1b565d

Please sign in to comment.