简体   繁体   English

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

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

When I comment out the constraints it works perfectly, but the problem is the height of the textfield becomes too small, when I add the heightConstraint , it works fine in my iPhone XS Max , but crashes in other Iphones... 当我注释掉约束时,它可以完美地工作,但是问题是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

}()

Would you please try this 你可以试试这个吗

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

instead of 代替

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

Try this first, if this doesnot solve your problem then remove bottomanchor 请先尝试执行此操作,如果这不能解决您的问题,请删除bottomanchor

Either use heightConstraint or use topAnchor and bottomAnchor . 使用heightConstraint或使用topAnchor和bottomAnchor Don't use both cause xcode will not understand what to do, you are just making it confuses by giving height and autolayout . 不要同时使用这两种方法,因为xcode无法理解该怎么做,您只是通过给出height和autolayout来使其混淆。

暂无
暂无

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

相关问题 我不了解并且不知道如何解决的ImagePicker IOS错误 - ImagePicker IOS errors i don't understand and don't know how to fix Xcode中的致命错误-我知道原因,但不知道如何解决 - Fatal error in Xcode - I know the cause but don't know how to fix it 我不知道如何将弹出框与按钮对齐 - I don't know how to align my popovers to button 我不知道为什么这个表视图代码崩溃了 - i don't know why this table view code crashes 当弹丸击中两个“怪物”时,didBeginContact方法崩溃。 我知道为什么,但我不知道如何避免 - When projectile hits two “monsters” the didBeginContact method crashes. I know why but i don't know how to avoid it UIEdgeInsetsMake在单元格上创建一个奇怪的乐队,我不知道如何解决它 - UIEdgeInsetsMake creating a weird band on the cell, and I don't know how to fix it 不知道如何在iOS上从我的应用程序委托访问视图对象 - Don't know how to access a view object from my app delegate on iOS 我需要帮助在我的 API 代码中实现不记名令牌,但我不知道如何:( - I need help implementing Bearer Token in my API code but I don't know how :( 我有一个有效的滑动检测器脚本,但我不知道如何将它连接到我的角色控制器 - I have a working swipe detector script, but I don't know how to connect it to my character controller UIViewController.storyboard 必须仅在主线程中使用 - 新错误我不知道如何修复? - UIViewController.storyboard must be used from main thread only - New Error I don't know how to fix?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM