gpt4 book ai didi

ios - 动态更改 preferredContentSize?

转载 作者:行者123 更新时间:2023-11-28 08:45:04 27 4
gpt4 key购买 nike

我想根据一些设置更改模态框的 preferredContentSize。

例如:有一个开关,如果开关关闭,我想隐藏一些Cells。很好,但我还想调整模式的大小。

我会正常调整它的大小:

var contentSize = CGSizeMake(560, 562)

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.preferredContentSize = contentSize
}

@IBAction func photoSwitchPressed(sender: UISwitch) {
if sender.on == true {
photos = true
} else {
photos = false
contentSize = CGSizeMake(560, 462) // resize?
self.viewWillAppear(true) // how to force resize?
}
tableView.reloadData()
}

有什么想法吗?提前致谢。

最佳答案

您是否尝试将 tableView 的 footerview 设置得非常小?

swift 3

var contentSize = CGSize(width: 560, height: 562)
var photos = false

override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
}

override func viewWillAppear(_ animated: Bool) {
preferredContentSize = contentSize
}

@IBAction func photoSwitchPressed(_ sender: UISwitch) {
if sender.isOn == true {
photos = true
} else {
photos = false
contentSize = CGSize(width: 560, height: 462)

}
tableView.reloadData()
}

关于ios - 动态更改 preferredContentSize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35544036/

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