![](/img/trans.png)
[英]ImagePicker IOS errors i don't understand and don't know how to fix
[英]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.