【发布时间】:2018-02-12 13:29:59
【问题描述】:
在 iOS 11 中,更改 UIView 的转换属性(例如缩放)不会影响绑定到此视图的约束。在 iOS 10 中,一切都按预期工作。
我的代码:
import UIKit
class TestViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
// top view
let topView = UIView()
topView.frame = CGRect(x: 100, y: 100, width: 200, height: 100)
topView.backgroundColor = .black
view.addSubview(topView)
topView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
// bottom view
let bottomView = UIView()
bottomView.translatesAutoresizingMaskIntoConstraints = false
bottomView.backgroundColor = .black
view.addSubview(bottomView)
NSLayoutConstraint.activate([
bottomView.heightAnchor.constraint(equalToConstant: 200),
bottomView.widthAnchor.constraint(equalToConstant: 200),
bottomView.leftAnchor.constraint(equalTo: topView.leftAnchor),
bottomView.topAnchor.constraint(equalTo: topView.bottomAnchor, constant: 8)
])
}
}
我期待什么(iOS 10):
我有什么拥有(iOS 11):
如您所见,topView 已缩放,但 bottomView 布局不正确。我该如何解决?
【问题讨论】:
标签: ios swift autolayout ios11