UIPopOver从UIButton for iPhone

我们可以在iOS设备上用UIPopOver创buildiPad,使用Swift ,其源代码是UIButton 。 我创buildUIPopOverUIBarButtonItem和它的工作正常,但它不工作的情况下UIButton 。 任何人都可以提出更好的解决scheme尽快。 我需要在iPhone设备上工作。

是的,你可以,但你需要实现popoverPresentationController委托

 let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("AnnotationInfoViewController") as! PopUpViewController //If you want to show view from XIB file you can create viewController instance like this //let viewController = UIViewController() //let myView = NSBundle.mainBundle().loadNibNamed("PopUpView", owner: self, options: nil)[0] as! PopUpView //viewController.view = myView //Pass the information that you want to show viewController.data = passdata //Set the viewController for popoverPresentationController viewController.modalPresentationStyle = .Popover viewController.preferredContentSize = CGSize(width: viewController.view.frame.size.width, height: 80) viewController.popoverPresentationController!.delegate = self; viewController.popoverPresentationController!.permittedArrowDirections = [.Up , .Down] viewController.popoverPresentationController!.sourceView = yourBtn! viewController.popoverPresentationController!.sourceRect = yourBtn.frame self.presentViewController(viewController, animated: true, completion: nil) 

现在在您的ViewController实现popoverPresentationController这个方法

 func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { return .None; }