ios - NSLayoutConstraint 在 ios 10.0 或更低版本中无法正常工作,但在 11.0 中可以正常工作

标签 ios swift nslayoutconstraint

这是针对警报 Controller 进行编程编码的:

*This*它在 iOS 中运行良好11.0及以上,但我在 iOS 中遇到冲突10.0及以下

let vc = UIViewController()
var height:NSLayoutConstraint = NSLayoutConstraint(item: alert.view, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 0.6, constant: vc.view.frame.height * 0.53)
alert.view.addConstraint(height);
if(isIPadTrait){
    height = NSLayoutConstraint(item: alert.view, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 0.6, constant: vc.view.frame.height * 0.4)
}

最佳答案

您的代码假设警报 View 中定义了一个height约束,但情况可能是这样,也可能不是。 View 当然有一个定义的高度,但它可以在旧版本中动态计算或不使用布局约束。

关于ios - NSLayoutConstraint 在 ios 10.0 或更低版本中无法正常工作,但在 11.0 中可以正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51414462/

相关文章:

iphone - 如何动态调整 scrollViewDidZoom 中的 contentInset?我最初在 UIScrollview 中设置了 UIImageView 的 contentInset

c++ - 从 Objective C 调用 C++

android - 为生产部署 django 应用程序的必要程序

ios - 如何以编程方式更改 UIButton 的画外音值?

ios - 在 Swift 中重命名 socket

swift - xcode:没有这样的模块 'Kingfisher'

Swift-如何接受多个(联合)类型作为参数

ios - 如何将顶部约束设置为屏幕高度的 20%?

ios - 单个自动布局约束更改会破坏整个布局

ios - 对象 swift 3.0 上的 NSLayoutConstraints