Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix which keeps from animating keyboardPanningActionHandler when keyboard is animated from a UINavigationController push #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 80 additions & 31 deletions DAKeyboardControl/DAKeyboardControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,21 @@ - (void)inputKeyboardWillShow:(NSNotification *)notification
CGRect keyboardEndFrameWindow;
[[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardEndFrameWindow];

CGRect keyboardBeginFrameWindow;
[[notification.userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] getValue: &keyboardBeginFrameWindow];


double keyboardTransitionDuration;
[[notification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&keyboardTransitionDuration];

UIViewAnimationCurve keyboardTransitionAnimationCurve;
[[notification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&keyboardTransitionAnimationCurve];

if(keyboardEndFrameWindow.origin.y == keyboardBeginFrameWindow.origin.y) {
//same origin, keyboard is being presenting in a navigation controller push
keyboardTransitionDuration = 0;
}

self.keyboardActiveView.hidden = NO;
self.keyboardOpened = YES;

Expand All @@ -250,27 +259,48 @@ - (void)inputKeyboardWillShow:(NSNotification *)notification
if (constraintBasedKeyboardDidMoveBlockCalled)
self.constraintBasedKeyboardDidMoveBlock(keyboardEndFrameView, YES, NO);

[UIView animateWithDuration:keyboardTransitionDuration
delay:0.0f
options:AnimationOptionsForCurve(keyboardTransitionAnimationCurve) | UIViewAnimationOptionBeginFromCurrentState
animations:^{
if (constraintBasedKeyboardDidMoveBlockCalled)
[self layoutIfNeeded];
if (self.frameBasedKeyboardDidMoveBlock && !CGRectIsNull(keyboardEndFrameView))
self.frameBasedKeyboardDidMoveBlock(keyboardEndFrameView, YES, NO);
}
completion:^(__unused BOOL finished){
if (self.panning && !self.keyboardPanRecognizer)
{
// Register for gesture recognizer calls
self.keyboardPanRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(panGestureDidChange:)];
[self.keyboardPanRecognizer setMinimumNumberOfTouches:1];
[self.keyboardPanRecognizer setDelegate:self];
[self.keyboardPanRecognizer setCancelsTouchesInView:NO];
[self addGestureRecognizer:self.keyboardPanRecognizer];
if(keyboardTransitionDuration > 0) {

[UIView animateWithDuration:keyboardTransitionDuration
delay:0.0f
options:AnimationOptionsForCurve(keyboardTransitionAnimationCurve) | UIViewAnimationOptionBeginFromCurrentState
animations:^{
if (constraintBasedKeyboardDidMoveBlockCalled)
[self layoutIfNeeded];
if (self.frameBasedKeyboardDidMoveBlock && !CGRectIsNull(keyboardEndFrameView))
self.frameBasedKeyboardDidMoveBlock(keyboardEndFrameView, YES, NO);
}
}];
completion:^(__unused BOOL finished){
if (self.panning && !self.keyboardPanRecognizer)
{
// Register for gesture recognizer calls
self.keyboardPanRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(panGestureDidChange:)];
[self.keyboardPanRecognizer setMinimumNumberOfTouches:1];
[self.keyboardPanRecognizer setDelegate:self];
[self.keyboardPanRecognizer setCancelsTouchesInView:NO];
[self addGestureRecognizer:self.keyboardPanRecognizer];
}
}];
}
else {

if (constraintBasedKeyboardDidMoveBlockCalled)
[self layoutIfNeeded];
if (self.frameBasedKeyboardDidMoveBlock && !CGRectIsNull(keyboardEndFrameView))
self.frameBasedKeyboardDidMoveBlock(keyboardEndFrameView, YES, NO);

if (self.panning && !self.keyboardPanRecognizer)
{
// Register for gesture recognizer calls
self.keyboardPanRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(panGestureDidChange:)];
[self.keyboardPanRecognizer setMinimumNumberOfTouches:1];
[self.keyboardPanRecognizer setDelegate:self];
[self.keyboardPanRecognizer setCancelsTouchesInView:NO];
[self addGestureRecognizer:self.keyboardPanRecognizer];
}
}
}

- (void)inputKeyboardDidShow
Expand All @@ -291,12 +321,20 @@ - (void)inputKeyboardDidShow

- (void)inputKeyboardWillChangeFrame:(NSNotification *)notification
{
CGRect keyboardBeginFrameWindow;
[[notification.userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] getValue: &keyboardBeginFrameWindow];

CGRect keyboardEndFrameWindow;
[[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardEndFrameWindow];

double keyboardTransitionDuration;
[[notification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&keyboardTransitionDuration];

if(keyboardEndFrameWindow.origin.y == keyboardBeginFrameWindow.origin.y) {
//same origin, keyboard is being presenting in a navigation controller push
keyboardTransitionDuration = 0;
}

UIViewAnimationCurve keyboardTransitionAnimationCurve;
[[notification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&keyboardTransitionAnimationCurve];

Expand All @@ -306,17 +344,28 @@ - (void)inputKeyboardWillChangeFrame:(NSNotification *)notification
if (constraintBasedKeyboardDidMoveBlockCalled)
self.constraintBasedKeyboardDidMoveBlock(keyboardEndFrameView, NO, NO);

[UIView animateWithDuration:keyboardTransitionDuration
delay:0.0f
options:AnimationOptionsForCurve(keyboardTransitionAnimationCurve) | UIViewAnimationOptionBeginFromCurrentState
animations:^{
if (constraintBasedKeyboardDidMoveBlockCalled)
[self layoutIfNeeded];

if (self.frameBasedKeyboardDidMoveBlock && !CGRectIsNull(keyboardEndFrameView))
self.frameBasedKeyboardDidMoveBlock(keyboardEndFrameView, NO, NO);
}
completion:nil];
if(keyboardTransitionDuration > 0) {

[UIView animateWithDuration:keyboardTransitionDuration
delay:0.0f
options:AnimationOptionsForCurve(keyboardTransitionAnimationCurve) | UIViewAnimationOptionBeginFromCurrentState
animations:^{
if (constraintBasedKeyboardDidMoveBlockCalled)
[self layoutIfNeeded];

if (self.frameBasedKeyboardDidMoveBlock && !CGRectIsNull(keyboardEndFrameView))
self.frameBasedKeyboardDidMoveBlock(keyboardEndFrameView, NO, NO);
}
completion:nil];
}
else {

if (constraintBasedKeyboardDidMoveBlockCalled)
[self layoutIfNeeded];

if (self.frameBasedKeyboardDidMoveBlock && !CGRectIsNull(keyboardEndFrameView))
self.frameBasedKeyboardDidMoveBlock(keyboardEndFrameView, NO, NO);
}
}

- (void)inputKeyboardDidChangeFrame
Expand Down