如何:将子视图约束到safeArea Obj-c [英] How to: Constrain subview to safeArea Obj-c

查看:81
本文介绍了如何:将子视图约束到safeArea Obj-c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为iPhone X及更高版本更新此约束代码?该代码不支持新的视图大小,我认为可以对其进行一些改动以适应新的规范.是否应该在保存 addConstraint 的函数中进行更新?

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

推荐答案

谢谢大家的回答,我最终为委托创建了一个扩展并以这种方式处理了约束.对于将来使用不推荐使用的JSQMessages包的任何人,这将是有帮助的!再次感谢您的帮助.

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
        }
    }
}

这篇关于如何:将子视图约束到safeArea Obj-c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆