Skip to content

Commit

Permalink
Differentiate between the move block and the complete block (for pann…
Browse files Browse the repository at this point in the history
…ing vs non-panning)
  • Loading branch information
danielamitay committed Dec 26, 2012
1 parent 3210c1b commit 43abdaf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DAKeyboardControl/DAKeyboardControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ typedef void (^DAKeyboardDidMoveBlock)(CGRect keyboardFrameInView);
@property (nonatomic) CGFloat keyboardTriggerOffset;

- (void)addKeyboardPanningWithActionHandler:(DAKeyboardDidMoveBlock)didMoveBlock;
- (void)addKeyboardNonpanningWithActionHandler:(DAKeyboardDidMoveBlock)didMoveBlock;
- (void)addKeyboardNonpanningWithActionHandler:(DAKeyboardDidMoveBlock)didCompleteBlock;

- (void)removeKeyboardControl;

Expand Down
30 changes: 29 additions & 1 deletion DAKeyboardControl/DAKeyboardControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ static inline UIViewAnimationOptions AnimationOptionsForCurve(UIViewAnimationCur

static char UIViewKeyboardTriggerOffset;
static char UIViewKeyboardDidMoveBlock;
static char UIViewKeyboardDidCompleteBlock;
static char UIViewKeyboardActiveInput;
static char UIViewKeyboardActiveView;
static char UIViewKeyboardPanRecognizer;

@interface UIView (DAKeyboardControl_Internal) <UIGestureRecognizerDelegate>

@property (nonatomic) DAKeyboardDidMoveBlock keyboardDidMoveBlock;
@property (nonatomic) DAKeyboardDidMoveBlock keyboardDidCompleteBlock;
@property (nonatomic, assign) UIResponder *keyboardActiveInput;
@property (nonatomic, assign) UIView *keyboardActiveView;
@property (nonatomic, strong) UIPanGestureRecognizer *keyboardPanRecognizer;
Expand Down Expand Up @@ -83,7 +85,12 @@ - (void)addKeyboardNonpanningWithActionHandler:(DAKeyboardDidMoveBlock)actionHan

- (void)addKeyboardControl:(BOOL)panning actionHandler:(DAKeyboardDidMoveBlock)actionHandler
{
self.keyboardDidMoveBlock = actionHandler;
if (panning)
{
self.keyboardDidMoveBlock = actionHandler;
}

self.keyboardDidCompleteBlock = actionHandler;

// Register for text input notifications
[[NSNotificationCenter defaultCenter] addObserver:self
Expand Down Expand Up @@ -191,6 +198,7 @@ - (void)removeKeyboardControl

// Release a few properties
self.keyboardDidMoveBlock = nil;
self.keyboardDidCompleteBlock = nil;
self.keyboardActiveInput = nil;
self.keyboardActiveView = nil;
self.keyboardPanRecognizer = nil;
Expand Down Expand Up @@ -287,6 +295,8 @@ - (void)inputKeyboardWillChangeFrame:(NSNotification *)notification
self.keyboardDidMoveBlock(keyboardEndFrameView);
}
completion:^(BOOL finished){
if(self.keyboardDidCompleteBlock)
self.keyboardDidCompleteBlock(keyboardEndFrameView);
}];
}

Expand Down Expand Up @@ -316,6 +326,8 @@ - (void)inputKeyboardWillHide:(NSNotification *)notification
self.keyboardDidMoveBlock(keyboardEndFrameView);
}
completion:^(BOOL finished){
if(self.keyboardDidCompleteBlock)
self.keyboardDidCompleteBlock(keyboardEndFrameView);
}];
}

Expand Down Expand Up @@ -541,6 +553,22 @@ - (void)setKeyboardDidMoveBlock:(DAKeyboardDidMoveBlock)keyboardDidMoveBlock
[self didChangeValueForKey:@"keyboardDidMoveBlock"];
}

- (DAKeyboardDidMoveBlock)keyboardDidCompleteBlock
{
return objc_getAssociatedObject(self,
&UIViewKeyboardDidCompleteBlock);
}

- (void)setKeyboardDidCompleteBlock:(DAKeyboardDidMoveBlock)keyboardDidCompleteBlock
{
[self willChangeValueForKey:@"keyboardDidCompleteBlock"];
objc_setAssociatedObject(self,
&UIViewKeyboardDidCompleteBlock,
keyboardDidCompleteBlock,
OBJC_ASSOCIATION_COPY);
[self didChangeValueForKey:@"keyboardDidCompleteBlock"];
}

- (CGFloat)keyboardTriggerOffset
{
NSNumber *keyboardTriggerOffsetNumber = objc_getAssociatedObject(self,
Expand Down

0 comments on commit 43abdaf

Please sign in to comment.