objective-cconstraintsjsqmessagesviewcontroller

How to: Constrain subview to safeArea Obj-c


How can I update this constraint code for iPhone X and up? This code doesn't support the new sizes of views and I feel as if it could be altered just a bit to fit the new specifications. Should an update be made in the function that holds addConstraint ?

@implementation UIView (JSQMessages)


- (void)jsq_pinSubview:(UIView *)subview toEdge:(NSLayoutAttribute)attribute
{


    [self addConstraint:[NSLayoutConstraint constraintWithItem:self
                                                     attribute:attribute
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:subview
                                                     attribute:attribute
                                                    multiplier:1.0f
                                                      constant:0.0f]];

}

- (void)jsq_pinAllEdgesOfSubview:(UIView *)subview
{


    [self jsq_pinSubview:subview toEdge:NSLayoutAttributeBottom];
    [self jsq_pinSubview:subview toEdge:NSLayoutAttributeTop];
    [self jsq_pinSubview:subview toEdge:NSLayoutAttributeLeading];
    [self jsq_pinSubview:subview toEdge:NSLayoutAttributeTrailing];
}

@end

Solution

  • Thank you all for the answers, I ended up creating an extension for the delegate and handled constraints that way. This will be helpful in the future for anyone using the deprecated JSQMessages package! Thanks again for the help.

    extension JSQMessagesInputToolbar {
    override open func didMoveToWindow() {
        super.didMoveToWindow()
        if #available(iOS 11.0, *), let window = self.window {
            let anchor = window.safeAreaLayoutGuide.bottomAnchor
            bottomAnchor.constraint(lessThanOrEqualToSystemSpacingBelow: anchor, multiplier: 0.3).isActive = true
            }
        }
    }