Ios SystemLayoutSizeFiting未返回正确的视图大小
我正在将视图控制器的视图设置为UITableView的标题Ios SystemLayoutSizeFiting未返回正确的视图大小,ios,swift,uitableview,uinavigationcontroller,Ios,Swift,Uitableview,Uinavigationcontroller,我正在将视图控制器的视图设置为UITableView的标题 var headerView = CommunityPostDetailTableHeaderViewController() override func viewDidLoad() { // other stuffs headerView.view.frame = CGRect(x: 0, y: 0, width: self.tableView.frame.size.width, height: 100) he
var headerView = CommunityPostDetailTableHeaderViewController()
override func viewDidLoad() {
// other stuffs
headerView.view.frame = CGRect(x: 0, y: 0, width: self.tableView.frame.size.width, height: 100)
headerView.delegate = self
self.tableView.tableHeaderView = headerView.view
}
并使用这段代码根据视图大小调整其大小
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if let headerView = tableView.tableHeaderView {
let height = headerView.systemLayoutSizeFitting(CGSize(width: tableView.bounds.width, height: 0)).height
var headerFrame = headerView.frame
// Comparison necessary to avoid infinite loop
if height != headerFrame.size.height {
headerFrame.size.height = height
headerView.frame = headerFrame
tableView.tableHeaderView = headerView
}
}
}
我在两个表视图中使用了这种技术
您正在使用全屏,但您的图像是固定大小的图像。粉红色视图也有固定大小。 也许这是个问题 这实际上不是一个答案。给你一个建议。您可以再次检查代码。希望你能找到
快乐编码如果不是答案,请不要将其放在答案字段中。我试图帮助他。没有人回答,然后我得到-1哈哈。美好的
let playerController = VideoDetailController()
playerController.modalPresentationStyle = .fullScreen
playerController.video = video
self.present(playerController, animated: true, completion: nil)
let communityPostDetailVC = CommunityPostDetailViewController()
communityPostDetailVC.delegate = self
if let indexpath = indexpath {
communityPostDetailVC.communityPost = datasource[indexpath.row]
communityPostDetailVC.indexpath = indexpath
}
let navigationController = UINavigationController(rootViewController: communityPostDetailVC)
navigationController.modalPresentationStyle = .fullScreen
self.present(navigationController, animated: true)