簡體   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