如何使我的内容位于导航 Controller 下方,而无需以编程方式调整内容 y 位置。我问这个问题的原因是因为当我使用 y 位置调整内容时,它看起来很好,但是当设备旋转时,我会得到一个白色间隙,因为导航栏高度发生了变化。
我的代码
import UIKit
class ProfileViewController: UINavigationController {
let topProfileView = UIView()
override func viewDidLoad() {
view.backgroundColor = .white
topProfileView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(topProfileView)
topProfileView.backgroundColor = .red
topProfileView.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 0).isActive = true
topProfileView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true
topProfileView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true
topProfileView.heightAnchor.constraint(equalToConstant: 100).isActive = true
topProfileView.topAnchor.constraint(equalTo: view.topAnchor, constant:44).isActive = true
}
最佳答案
您可以使用自动布局来做到这一点。 自动布局中红色 View 的x和y位置为0
关于swift - 如何使我的内容位于导航 Controller 下方,而不以编程方式调整内容 y 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39764926/