繁体   English   中英

我的应用由于高度限制而崩溃,我不知道如何解决

[英]My App crashes because of the heightConstraints I don't know how to fix it

当我注释掉约束时,它可以完美地工作,但是问题是textfield的高度变得太小,当我添加heightConstraint ,它在我的iPhone XS Max可以正常工作,但是在其他iPhone XS Max崩溃...

lazy var textField: MaterialTexField = { //MaterialTexField

    let tf = MaterialTexField()
    tf.translatesAutoresizingMaskIntoConstraints = false
    self.contentView.addSubview(tf)

    NSLayoutConstraint.activate([
        tf.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor, constant:16.0),
        tf.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor, constant:-16.0),
        tf.topAnchor.constraint(equalTo: self.contentView.topAnchor, constant:8.0),
        tf.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 1),
//This is the problematic constraints
        tf.heightAnchor.constraint(lessThanOrEqualTo:self.contentView.heightAnchor, multiplier:0.9)

    return tf

}()

你可以试试这个吗

tf.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor, constant: 1.0),

代替

tf.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 1),
tf.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor, constant: 1)

请先尝试执行此操作,如果这不能解决您的问题,请删除bottomanchor

使用heightConstraint或使用topAnchor和bottomAnchor 不要同时使用这两种方法,因为xcode无法理解该怎么做,您只是通过给出height和autolayout来使其混淆。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM