[英]Swift: Change height of UINavigationController view
I have a UITableView embedded in a UINavigationController.我有一个 UITableView 嵌入在 UINavigationController 中。 The UITableView is set up as follows:
UITableView 设置如下:
import UIKit
class HistoryTableViewController: UITableViewController {
let cellID = "HistoryColumns"
struct CellData {
let date: String?
let number: String?
let before: String?
let after: String?
let diff: String?
let strength: String?
let location: String?
}
var data = [CellData]()
override func viewDidLoad() {
super.viewDidLoad()
data = [
// data goes here
]
tableView.register(HistoryTableViewCell.self, forCellReuseIdentifier: cellID)
self.navigationController?.navigationBar.topItem?.title = "Recent Activity"
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellID) as! HistoryTableViewCell
if indexPath.row % 2 == 0 {
cell.backgroundColor = UIColor.orange.withAlphaComponent(0.3)
}
cell.date.valueLabel.text = data[indexPath.row].date
cell.number.valueLabel.text = data[indexPath.row].flightNumber
cell.before.valueLabel.text = data[indexPath.row].preFuel
cell.after.valueLabel.text = data[indexPath.row].postFuel
cell.diff.valueLabel.text = data[indexPath.row].uplift
cell.strength.valueLabel.text = data[indexPath.row].density
cell.location.valueLabel.text = data[indexPath.row].location
return cell
}
}
I call the controller within a UINavigationController as follows:我在 UINavigationController 中调用 controller 如下:
@objc func handleTap(_ sender: UITapGestureRecognizer? = nil) {
DispatchQueue.asyncMain {
let history = HistoryTableViewController()
let navigationController = UINavigationController(rootViewController: history)
self.present(navigationController, animated: true, completion: nil)
}
}
What I want to do is to define the height of the navigationController's view here (around 500).我要做的是在这里定义navigationController的视图高度(大约500)。 I've tried using navigationController.view.heightAnchor.constraint but it had no effect (obviously I set translatesAutoresizingMaskIntoConstraints to false first)...
我试过使用 navigationController.view.heightAnchor.constraint 但它没有效果(显然我首先将 translatesAutoresizingMaskIntoConstraints 设置为 false)......
I do want to use a UINavigationController here because I need the navbar that comes with it.我确实想在这里使用 UINavigationController 因为我需要它附带的导航栏。 Any suggestions greatly appreciated...
任何建议都非常感谢...
When you say .present
, the way the presented view controller occupies the screen is up to you.当您说
.present
时,呈现的视图 controller 占据屏幕的方式取决于您。 Make a custom transition and supply your own UIPresentationController subclass with an implementation of frameOfPresentedViewInContainerView
to say where the presented view controller's view should go.进行自定义转换并为您自己的 UIPresentationController 子类提供
frameOfPresentedViewInContainerView
的实现,以说明呈现的视图控制器的视图应位于 go 的位置。
This is a silly example with a custom animation as well, but you don't have to customize the animation if you don't want to.这是一个自定义 animation 的愚蠢示例,但如果您不想自定义 animation,则不必自定义。 The important thing is that I've made the presented view controller smaller than it normally would be.
重要的是,我使呈现的视图 controller 比正常情况小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.