I have a messaging app that has the typical UI design of a text field at the bottom of a full screen table view. I am setting that text field to be the view controller's inputAccessoryView
and calling ViewController.becomeFirstResponder()
in order to get the field to show at the bottom of the screen.
I understand this is the Apple recommended way of accomplishing this UI structure and it works perfectly on "classic" devices however when I test on the iPhone X simulator I notice that using this approach, the text field does not respect the new "safe areas". The text field is rendered at the very bottom of the screen underneath the home screen indicator.
I have looked around the the HIG documents but haven't found anything useful regarding the inputAccessoryView
on a view controller.
It's difficult because using this approach I'm not actually in control of any of the constraints directly, I'm just setting the inputAccessoryView
and letting the view controller handle the UI from there. So I can't just constrain the field to the new safe areas.
Has anyone found good documentation on this or know of an alternate approach that works well on the iPhone X?
inputAccessoryView
and safe area on iPhone Xwhen the keyboard is not visible, the
inputAccessoryView
is pinned on the very bottom of the screen. There is no way around that and I think this is intended behavior.the
layoutMarginsGuide
(iOS 9+) andsafeAreaLayoutGuide
(iOS 11) properties of the view set asinputAccessoryView
both respect the safe area, i.e on iPhone X :bottomAnchor
accounts for the home button areabottomAnchor
is at the bottom of theinputAccessoryView
, so that it leaves no useless space above the keyboardWorking example :
See the result here
In Xib, find a right constraint at the bottom of your design, and set item to
Safe Area
instead ofSuperview
:Before:
Fix:
After:
This is a general issue with inputAccessoryViews on iPhone X. The inputAccessoryView ignores the safeAreaLayoutGuides of its window.
To fix it you ou have to manually add the constraint in your class when the view moves to its window:
PS: self here is referring to the inputAccessoryView.
I wrote about it in detail here: http://ahbou.org/post/165762292157/iphone-x-inputaccessoryview-fix
Just add one extension for JSQMessagesInputToolbar
duplicate : jsqmessageviewcontroller ios11 toolbar
From code (Swift 4). Idea - monitoring
layoutMarginsDidChange
event and adjustingintrinsicContentSize
.Usage:
Result:
I just created a project on Github with support for iPhone X. It respects the new safe area layout guide. Use:
Screenshot: