Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Animate views when switching from the a keyboard to a custom input view. #416

Merged
merged 1 commit into from
Mar 23, 2016
Merged
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
6 changes: 5 additions & 1 deletion Source/SLKTextViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,9 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
[self slk_hideAutoCompletionViewIfNeeded];
}

// store the previous keyboard height
CGFloat preKeyboardHeight = self.keyboardHC.constant;

// Updates the height constraints' constants
self.keyboardHC.constant = [self slk_appropriateKeyboardHeightFromNotification:notification];
self.scrollViewHC.constant = [self slk_appropriateScrollViewHeight];
Expand All @@ -1397,7 +1400,8 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification

// Begin and end frames are the same when the keyboard is shown during navigation controller's push animation.
// The animation happens in window coordinates (slides from right to left) but doesn't in the view controller's view coordinates.
if (!CGRectEqualToRect(beginFrame, endFrame))
// Second condition: check if the height of the keyboard changed.
if (!CGRectEqualToRect(beginFrame, endFrame) || fabs(preKeyboardHeight - self.keyboardHC.constant) >= FLT_EPSILON)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! Is the difference really small as FLT_EPSILON?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of my habit when dealing with floating point numbers. 😛
As you mentioned, a direct comparison will do the work and there should not affect anything at UI level.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello
how you put custom view in keyboard place ?!

Copy link
Contributor Author

@cyhsutw cyhsutw Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SLAMAKA You can do this by setting inputView to any kind of UIResponder.

Reference: https://developer.apple.com/library/content/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html

Since this is not relevant to this pull request, could we move the discussion to a private email thread, feel free to drop me a message at m@cyhsu.me

Thanks.

{
// Only for this animation, we set bo to bounce since we want to give the impression that the text input is glued to the keyboard.
[self.view slk_animateLayoutIfNeededWithDuration:duration
Expand Down