在 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)
])
}
}
我该怎么办expect(iOS 10):
我该怎么办have(iOS 11):
如你看到的,topView
缩放,但是bottomView
布局不正确。我该如何修复它?
来自苹果的UIView / Transform
Docs (https://developer.apple.com/documentation/uikit/uiview/1622459-transform https://developer.apple.com/documentation/uikit/uiview/1622459-transform):
Warning
当该属性的值不是恒等变换时,frame 属性中的值是未定义的,并且
应该被忽略。
所以,你在 iOS 10 中得到的结果恰好是你得到了什么,而不是它本身正确的 result.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)