2016-08-10 34 views
0

我们可以在iPhone设备上使用Swift创建iPad,如UIPopOver,其中源是UIButton。我创建了UIPopOverUIBarButtonItem和它的工作正常,但它不工作的情况下UIButton。任何人都可以提出更好的解决方案尽快。我需要在iPhone设备上工作。UIPopOver来自UIButton for iPhone

+0

看到这个http://stackoverflow.com/questions/的popoverPresentationController这种方法28521583/uipopoverpresentationcontroller-ON-iphone-犯规-农产品-酥料饼 –

回答

1

当然可以,但你需要实现的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

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