Browse files

Block now returns the keyboard's frame. Useful for more complicated i…

…nterface changes.
  • Loading branch information...
1 parent eb82886 commit df6175697a6181bbacb0b7753e6817993ece708f @danielamitay committed Jul 20, 2012
View
4 DAKeyboardControl/DAKeyboardControl.h
@@ -8,7 +8,7 @@
#import <UIKit/UIKit.h>
-typedef void (^DAKeyboardDidMoveBlock)(CGPoint keyboardOriginInView);
+typedef void (^DAKeyboardDidMoveBlock)(CGRect keyboardFrameInView);
@interface UIView (DAKeyboardControl)
@@ -19,6 +19,6 @@ typedef void (^DAKeyboardDidMoveBlock)(CGPoint keyboardOriginInView);
- (void)removeKeyboardControl;
-- (CGPoint)keyboardOriginInView;
+- (CGRect)keyboardFrameInView;
@end
View
26 DAKeyboardControl/DAKeyboardControl.m
@@ -93,17 +93,21 @@ - (void)addKeyboardControl:(BOOL)panning actionHandler:(DAKeyboardDidMoveBlock)a
}
}
-- (CGPoint)keyboardOriginInView
+- (CGRect)keyboardFrameInView
{
if (self.keyboardActiveView)
{
- CGPoint keyboardWindowOrigin = self.keyboardActiveView.frame.origin;
- return [self convertPoint:keyboardWindowOrigin fromView:self.keyboardActiveView.window];
+ CGRect keyboardFrameInView = [self convertRect:self.keyboardActiveView.frame
+ fromView:self.keyboardActiveView.window];
+ return keyboardFrameInView;
}
else
{
- CGPoint keyboardWindowOrigin = CGPointMake(0.0f, [[UIScreen mainScreen] bounds].size.height);
- return [self convertPoint:keyboardWindowOrigin fromView:self.keyboardActiveView.window];
+ CGRect keyboardFrameInView = CGRectMake(0.0f,
+ [[UIScreen mainScreen] bounds].size.height,
+ 0.0f,
+ 0.0f);
+ return keyboardFrameInView;
}
}
@@ -188,7 +192,7 @@ - (void)keyboardWillShow:(NSNotification *)notification
options:keyboardTransitionAnimationCurve
animations:^{
if (self.keyboardDidMoveBlock)
- self.keyboardDidMoveBlock(keyboardEndFrameView.origin);
+ self.keyboardDidMoveBlock(keyboardEndFrameView);
}
completion:^(BOOL finished){
}];
@@ -226,7 +230,7 @@ - (void)keyboardWillChangeFrame:(NSNotification *)notification
options:keyboardTransitionAnimationCurve
animations:^{
if (self.keyboardDidMoveBlock)
- self.keyboardDidMoveBlock(keyboardEndFrameView.origin);
+ self.keyboardDidMoveBlock(keyboardEndFrameView);
}
completion:^(BOOL finished){
}];
@@ -255,7 +259,7 @@ - (void)keyboardWillHide:(NSNotification *)notification
options:keyboardTransitionAnimationCurve
animations:^{
if (self.keyboardDidMoveBlock)
- self.keyboardDidMoveBlock(keyboardEndFrameView.origin);
+ self.keyboardDidMoveBlock(keyboardEndFrameView);
}
completion:^(BOOL finished){
}];
@@ -332,7 +336,7 @@ - (void)panGestureDidChange:(UIPanGestureRecognizer *)gesture
animations:^{
[self.keyboardActiveView setFrame:newKeyboardViewFrame];
if (self.keyboardDidMoveBlock)
- self.keyboardDidMoveBlock(newKeyboardViewFrameInView.origin);
+ self.keyboardDidMoveBlock(newKeyboardViewFrameInView);
}
completion:^(BOOL finished){
}];
@@ -355,7 +359,7 @@ - (void)panGestureDidChange:(UIPanGestureRecognizer *)gesture
animations:^{
[self.keyboardActiveView setFrame:newKeyboardViewFrame];
if (self.keyboardDidMoveBlock)
- self.keyboardDidMoveBlock(newKeyboardViewFrameInView.origin);
+ self.keyboardDidMoveBlock(newKeyboardViewFrameInView);
}
completion:^(BOOL finished){
if (!within44Pixels)
@@ -383,7 +387,7 @@ - (void)panGestureDidChange:(UIPanGestureRecognizer *)gesture
animations:^{
[self.keyboardActiveView setFrame:newKeyboardViewFrame];
if (self.keyboardDidMoveBlock)
- self.keyboardDidMoveBlock(newKeyboardViewFrameInView.origin);
+ self.keyboardDidMoveBlock(newKeyboardViewFrameInView);
}
completion:^(BOOL finished){
if (!within44Pixels)
View
4 DAKeyboardControlExample/DAKeyboardControlExample/ViewController.m
@@ -56,7 +56,7 @@ - (void)viewDidLoad
self.view.keyboardTriggerOffset = toolBar.bounds.size.height;
- [self.view addKeyboardPanningWithActionHandler:^(CGPoint keyboardOriginInView) {
+ [self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
/*
Try not to call "self" inside this block (retain cycle).
But if you do, make sure to remove DAKeyboardControl
@@ -65,7 +65,7 @@ - (void)viewDidLoad
*/
CGRect toolBarFrame = toolBar.frame;
- toolBarFrame.origin.y = keyboardOriginInView.y - toolBarFrame.size.height;
+ toolBarFrame.origin.y = keyboardFrameInView.origin.y - toolBarFrame.size.height;
toolBar.frame = toolBarFrame;
CGRect tableViewFrame = tableView.frame;
View
6 README.md
@@ -22,7 +22,7 @@ Example project included (DAKeyboardControlExample)
### Adding pan-to-dismiss (functionality introduced in iMessages)
```objective-c
-[self.view addKeyboardPanningWithActionHandler:^(CGPoint keyboardOriginInView) {
+[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
// Move interface objects accordingly
// Animation block is handled for you
}];
@@ -31,7 +31,7 @@ Example project included (DAKeyboardControlExample)
### Adding keyboard awareness (appearance and disappearance only)
```objective-c
-[self.view addKeyboardNonpanningWithActionHander:^(CGPoint keyboardOriginInView) {
+[self.view addKeyboardNonpanningWithActionHander:^(CGRect keyboardFrameInView) {
// Move interface objects accordingly
// Animation block is handled for you
}];
@@ -44,7 +44,7 @@ The `keyboardTriggerOffset` property allows you to choose at what point the user
```objective-c
self.view.keyboardTriggerOffset = 44.0f; // Input view frame height
-[self.view addKeyboardPanningWithActionHandler:^(CGPoint keyboardOriginInView) {
+[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
// Move input view accordingly
// Animation block is handled for you
}];

0 comments on commit df61756

Please sign in to comment.