用程序创build的UIPopoverPresentationController在iPhone上强制popup
我需要创build一个新的弹窗视图,因为在编译期间在界面构build器中锚点是不可见的。
根据这篇文章 ,实施委托方法将迫使iPhone上的Popover。 (因为我不明白)
如在post中所显示的那样,在赛季中它很好用。 但是我不能以非循序渐进的方式工作。 (Popover在iPad上显示)
请帮忙!
代码如下:
func showOptions() { let contentView = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("PasteOption") as NewPasteOptionViewController contentView.modalPresentationStyle = UIModalPresentationStyle.Popover contentView.preferredContentSize = CGSizeMake(200.0, 200.0) presentViewController(contentView, animated: true, completion: nil) var _popoverPresentationController = contentView.popoverPresentationController! _popoverPresentationController.delegate = self _popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.Any _popoverPresentationController.sourceView = view _popoverPresentationController.sourceRect = self.navigationItem.titleView!.frame } // this function below is never called. func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { return UIModalPresentationStyle.None }
补充笔记:
呈现视图控制器在另一视图中作为模态表单呈现,并封装在导航控制器中。 呈现的视图控制器是一个自定义表视图控制器。
看来,将行presentViewController(contentView, animated: true, completion: nil)
到该函数的结尾将解决这个问题。
let contentView = PLMainNavigationManager.sharedInstance.storyboard.instantiateViewControllerWithIdentifier("PLSearchVCID") as! PLSearchVC contentView.modalPresentationStyle = UIModalPresentationStyle.Popover contentView.preferredContentSize = CGSizeMake(400.0, 500.0) var _popoverPresentationController = contentView.popoverPresentationController! _popoverPresentationController.delegate = self _popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.Any _popoverPresentationController.sourceView = self.view _popoverPresentationController.sourceRect = CGRectMake(-30, -280, 320, 400) PLMainNavigationManager.sharedInstance.navigationController?.presentViewController(contentView, animated: true, completion: nil)