gpt4 book ai didi

ios - 以编程方式创建的 UIViewController 被导航栏部分隐藏

转载 作者:行者123 更新时间:2023-11-29 05:24:17 25 4
gpt4 key购买 nike

我有一个 UIViewController我以编程方式创建的子类,无需 Interface Builder。该类名为 ColorController ,因为它编辑颜色。当我将其添加到 UINavigationController 内的弹出窗口时,其内容隐藏在导航栏下方。当 ColorController 时,这种情况不会发生。是从 IB Storyboard文件中提取的。

是否有一些我必须在我的 ColorController 上重写的属性或方法告诉它在导航 Controller 中调整其边界?

现在我所做的就是创建我的根 UIView (a ColorPicker )并将其设置为 self.viewloadView() .

class ColorController: UIViewController {

private let colorPicker: ColorPicker

init() {
colorPicker = ColorPicker()
}

override func loadView() {
self.view = colorPicker
}

enter image description here

最佳答案

不要重写loadView,重写viewDidLoad并添加colorPicker self.view

使用 SnapKit

colorPicker.snp.makeConstraints { (make) -> Void in
make.leading.trailing.bottom.equalTo(0)
make.top.equalTo(self.topLayoutGuide.snp.bottom);
}

使用 iOS UIKit

colorPicker.translatesAutoresizingMaskIntoConstraints = false

var constraints = [NSLayoutConstraint(item: colorPicker, attribute: .leading, relatedBy: .equal, toItem: self.view, attribute: .leading, multiplier: 1, constant: 0),
NSLayoutConstraint(item: colorPicker, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1, constant: 0),
NSLayoutConstraint(item: colorPicker, attribute: .trailing, relatedBy: .equal, toItem: self.view, attribute: .trailing, multiplier: 1, constant: 0)]

if #available(iOS 11.0, *) {
constraints.append(NSLayoutConstraint(item: colorPicker, attribute: .top, relatedBy: .equal, toItem: self.view.safeAreaLayoutGuide, attribute: .top, multiplier: 1, constant: 0))
} else {
constraints.append(NSLayoutConstraint(item: colorPicker, attribute: .top, relatedBy: .equal, toItem: self.topLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0))
}
self.view.addConstraints(constraints)

关于ios - 以编程方式创建的 UIViewController 被导航栏部分隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58352616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com