gpt4 book ai didi

ios - UIProgressView 约束问题

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

我有一个以编程方式添加到 Storyboard View 的 UIProgressView 以及将其放置在导航栏底部的约束。有一个菜单,打开时会暂时隐藏导航栏,关闭时会再次取消隐藏。打开和关闭此菜单后,UIProgressView 上的约束将其放置在窗口的最顶部,因此它会被导航栏隐藏。因此,在隐藏导航栏时,布局和约束似乎正在重新计算和应用。如何在取消隐藏导航栏后强制应用约束?我试过 layoutIfNeeded 无济于事。此外,了解 View 层次结构有点困难,因为 View 是嵌入在导航 Controller 中的 Storyboard放置 View ,但此 View 的自定义 View Controller 从 xib 加载自己的 View 。关于如何强制应用约束和破译 View 层次结构的任何想法?

最佳答案

没有看到您的代码是很难回答的。顺便说一句,这是可行的:

override func viewDidLoad() {
super.viewDidLoad()

// if VC is pushed in a navigation controller I add a progress bar
if let navigationVC = self.navigationController {

// create progress bar with .bar style and add it as subview
let progressBar = UIProgressView(progressViewStyle: .Bar)
navigationVC.navigationBar.addSubview(progressBar)

// create constraints
// NOTE: bottom constraint has 1 as constant value instead of 0; this way the progress bar will look like the one in Safari
let bottomConstraint = NSLayoutConstraint(item: navigationVC.navigationBar, attribute: .Bottom, relatedBy: .Equal, toItem: progressBar, attribute: .Bottom, multiplier: 1, constant: 1)
let leftConstraint = NSLayoutConstraint(item: navigationVC.navigationBar, attribute: .Leading, relatedBy: .Equal, toItem: progressBar, attribute: .Leading, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: navigationVC.navigationBar, attribute: .Trailing, relatedBy: .Equal, toItem: progressBar, attribute: .Trailing, multiplier: 1, constant: 0)

// add constraints
progressBar.translatesAutoresizingMaskIntoConstraints = false
navigationVC.view.addConstraints([bottomConstraint, leftConstraint, rightConstraint])
}
}

关于ios - UIProgressView 约束问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29333852/

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