Вот еще один вариант:
Filter(Negate(is.null), x)
Представьте себя как делегат контроллера popup view перед представлением и реализуйте метод делегата adaptivePresentationStyle(for:traitCollection:)
для возврата .none
. Это заставит popover перестать адаптироваться к iPhone в качестве полноэкранного представленного контроллера представления и превратиться в фактический popover, как на iPad.
Это полный рабочий пример, который представляет popover в ответ на кнопку tap:
class ViewController: UIViewController {
@IBAction func doButton(_ sender: Any) {
let vc = MyPopoverViewController()
vc.preferredContentSize = CGSize(400,500)
vc.modalPresentationStyle = .popover
if let pres = vc.presentationController {
pres.delegate = self
}
self.present(vc, animated: true)
if let pop = vc.popoverPresentationController {
pop.sourceView = (sender as! UIView)
pop.sourceRect = (sender as! UIView).bounds
}
}
}
extension ViewController : UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}
}