First: is there a way of gracefully animating the popover's size to the size of the view controller pushed onto the navigation controller, like Pages does for the three dots menu? When setting the navigation controller's preferredContentSize inside the pushed table view controller's viewWillAppear, first the push animation is run, and when it finishes, the popover is resized.
I've tried embedding the navigation controller in a UIViewController, which according to this answer should make both animations happen at the same time, but it didn't work for me.
Second: how to get the correct size to set as preferredContentSize? That would probably be the table view's contentSize (which, unless calling reloadData(), is .zero in viewWillAppear) plus the navigation view's title bar height. How can one calculate this, without having to sum the different parts manually? I tried observing content changes like this
class TableViewControllerInsidePopover: UITableViewController {
private var contentSizeObserver : NSKeyValueObservation?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
contentSizeObserver = tableView.observe(\.contentSize) { [weak self] tableView, _ in
self?.preferredContentSize = tableView.contentSize
self?.navigationController!.preferredContentSize = tableView.contentSize
}
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
contentSizeObserver?.invalidate()
contentSizeObserver = nil
}
}
Perhaps this would be the correct approach when both animations occur at the same time, but currently, when the popover resizes to a smaller size, the extra space at the bottom that is not covered by the table view appears transparent (until it is not visible anymore at the end of the resize animation).