Skip to content

Conversation

s4cha
Copy link
Member

@s4cha s4cha commented Dec 8, 2017

We have a set of signup screens that are pushed one after another.

Everything works fine if we call becomeFirstResponder() in viewDidAppear
the keyboardWillChangeFrame is called and everything works as expected.

The thing is calling becomeFirstResponder in viewDidAppear animates the keyboard.

If we want to have the keyboard stay in position (already shown) in the screens,
we can call becomeFirstResponder in viewDidLoad.

In iOS 11, the issue is that the keyboard notifications are not called if the keyboard is already on screen
so we end up with the button under the keyboard.
The underlying reason is that keyboardWillChangeFrame is not called on IOS11 if the keyboard stays shown between controllers, which seems quite logical actually.

The fix stores the previous keyboard height and sets in back up when setting up a new controller, only if the device is running iOS 11 :)


if #available(iOS 11.0, *) {
NSLayoutConstraint.activate([
heightAnchor.constraint(equalToConstant: Keyboard.shared.currentHeight),
Copy link
Member

Choose a reason for hiding this comment

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

Better to conditionally calculate only the constant in if-else here, leaving a single NSLayoutConstraint.activate([...]) part (no repeating code)

@maxkonovalov
Copy link
Member

@s4cha do you think the iOS 11 check is necessary at all for the height caching? Having the height ready doesn't seem to be a bad idea, just need to make sure it works correctly on all versions.

@s4cha
Copy link
Member Author

s4cha commented Dec 12, 2017

@maxkonovalov I agree, I narrowed it down to iOS 11 to be specific but as you point out, it adds unnecessary complexity.

@maxkonovalov
Copy link
Member

👍

@s4cha s4cha merged commit 42485f9 into master Dec 12, 2017
@s4cha s4cha deleted the iOS11Fix branch September 20, 2024 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants