无法在Swift 3.0中将视图控制器显示为弹出控制器
问题描述:
我试图将我的视图控制器添加为弹出控制器。但是,每当我使用代码时,视图会从底部滑动,而不是像我希望的那样。下面是我使用无法在Swift 3.0中将视图控制器显示为弹出控制器
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let popupVC = storyboard.instantiateViewController(withIdentifier: "WSFilterViewController") as! WSFilterViewController
popupVC.modalPresentationStyle = UIModalPresentationStyle .popover
popupVC.preferredContentSize = CGSize (width: 300, height:300)
let pVC = popupVC.popoverPresentationController
pVC?.permittedArrowDirections = UIPopoverArrowDirection.any
pVC?.delegate = self as? UIPopoverPresentationControllerDelegate
self.present(popupVC, animated: true, completion: nil)
显示
任何帮助可以理解的代码,我想它的形象。
在此先感谢
答
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let popupVC = storyboard.instantiateViewController(withIdentifier: "WSFilterViewController")
popupVC.modalPresentationStyle = UIModalPresentationStyle .popover
popupVC.preferredContentSize = CGSize(width: 170, height: 130)
popupVC.popoverPresentationController?.delegate = self
popupVC.popoverPresentationController?.sourceView = sender as? UIView // button
popupVC.popoverPresentationController?.sourceRect = (sender as AnyObject).bounds
self.present(popupVC, animated: true, completion: nil)
的问题是不同的东西,现在想通了。
谢谢大家
+0
它仍然采取整个屏幕@gurmandeep –
如文档所述:在横向紧凑环境中,此选项的行为与fullScreen相同。 – Kubba
你是在iPad或iPhone设备上? –
你缺少源码查看,sourceRect和委托 –