I know that this library is already deprecated, but has anyone fixed the problem with the inputToolBar and iPhone X? Currently the inputToolBar is partially covered.Check out the attached image.
Thanks in advance
I know that this library is already deprecated, but has anyone fixed the problem with the inputToolBar and iPhone X? Currently the inputToolBar is partially covered.Check out the attached image.
Thanks in advance
In case you don't want to change the code in the pod and use are more swifty-like extension you can use the following code:
extension JSQMessagesInputToolbar {
override open func didMoveToWindow() {
super.didMoveToWindow()
guard let window = window else { return }
if #available(iOS 11.0, *) {
let anchor = window.safeAreaLayoutGuide.bottomAnchor
bottomAnchor.constraintLessThanOrEqualToSystemSpacingBelow(anchor, multiplier: 1.0).isActive = true
}
}
}
Updated Samson's answer because it would crash when I left the screen. Checked to make sure it was not nil before setting the constraint.
-(void) didMoveToWindow{
[super didMoveToWindow];
if (@available(iOS 11.0, *)) {
UILayoutGuide *layoutGuide = self.window.safeAreaLayoutGuide;
if (layoutGuide != nil){
[[self bottomAnchor] constraintLessThanOrEqualToSystemSpacingBelowAnchor:layoutGuide.bottomAnchor multiplier:1.0].active = YES;
}
}
}
Guys I am the one asking jsqmessageviewcontroller ios11 toolbar and I have figured it out!
Just put the following code in the JSQMessagesInputToolbar.m. It seems that the inputtoolbar is placed in its own window, you need to access its window separately.
-(void) didMoveToWindow{
[super didMoveToWindow];
if (@available(iOS 11.0, *)) {
[[self bottomAnchor] constraintLessThanOrEqualToSystemSpacingBelowAnchor:self.window.safeAreaLayoutGuide.bottomAnchor multiplier:1.0].active = YES;
}
}
I think this is should be a better way to solve this problem by following steps:
1. Open JSQMessagesViewController.xib
2. Drag down the collection view's bottom layout constraint into JSQMessagesViewController.m named collectionViewBottomLayoutGuide.
3. Add this code to the bottom of JSQMessagesViewController.m.
- (void)viewSafeAreaInsetsDidChange {
[super viewSafeAreaInsetsDidChange];
self.toolbarBottomLayoutGuide.active = NO;
self.toolbarBottomLayoutGuide = [NSLayoutConstraint constraintWithItem:self.view.safeAreaLayoutGuide attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.inputToolbar attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0.0f];
self.toolbarBottomLayoutGuide.active = YES;
self.collectionViewBottomLayoutGuide.active = NO;
self.collectionViewBottomLayoutGuide = [NSLayoutConstraint constraintWithItem:self.view.safeAreaLayoutGuide attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.collectionView attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0.0f];
self.collectionViewBottomLayoutGuide.active = YES;
}
Adding a new constraint and leaving the old constraint which will lead to see the layout errors in xcode debug screen and xcode will break one of the constraint to be able to satisfy the layout. Even if you see the correct layout on the screen you may have different problems like not responding to the keyboard changes.
This may be solved better by changing the old constraint by following steps:
Slight improvement of @J-Bossi's answer, for those of us who can't deal with autolayout technically breaking...
Just removes the existing constraint first, then adds that new constraint
extension JSQMessagesInputToolbar {
override open func didMoveToWindow() {
super.didMoveToWindow()
guard let window = window else { return }
if #available(iOS 11.0, *) {
guard let constraint = (superview?.constraints.first { $0.secondAnchor == bottomAnchor }) else { return }
let anchor = window.safeAreaLayoutGuide.bottomAnchor
NSLayoutConstraint.deactivate([constraint])
bottomAnchor.constraintLessThanOrEqualToSystemSpacingBelow(anchor, multiplier: 1.0).isActive = true
}
}
}