【问题标题】:centerXAnchor is only available in iOS 9.0 or newer?centerXAnchor 仅适用于 iOS 9.0 或更高版本?
【发布时间】:2017-05-23 09:47:57
【问题描述】:

所以我正在尝试以编程方式添加约束:
我只是添加了两个约束,Xcode 已经开始向我展示:

centerXAnchor 仅适用于 iOS 9.0 或更高版本

这是我的代码:

var constraints = [NSLayoutConstraint]()

let centerImageX = imageView.centerXAnchor.constraint(equalTo: footerView.centerXAnchor)

let centerImageY = imageView.centerYAnchor.constraint(equalTo: footerView.centerYAnchor)

constraints = [centerImageX,centerImageY]

NSLayoutConstraint.activate(constraints)

我想分享的一件事可能令人难以置信,几天前我没有收到任何错误消息。

我的 Xcode 版本是8.2.1

我的部署目标也是8.0 及以上。所以,如果有人能告诉我或者可以为 iOS 8.0 转换或翻译相同的代码,那就太棒了!

【问题讨论】:

    标签: ios swift3 nslayoutconstraint xcode8.2


    【解决方案1】:

    这应该做同样的工作:

    self.view.addConstraint(NSLayoutConstraint(item: imageView, attribute: .centerX, relatedBy: .equal, toItem: footerView, attribute: .centerX, multiplier: 1.0, constant: 0))
    self.view.addConstraint(NSLayoutConstraint(item: imageView, attribute: .centerY, relatedBy: .equal, toItem: footerView, attribute: .centerY, multiplier: 1.0, constant: 0))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-10
      • 2018-07-04
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多