0

Can we create iPad like UIPopOver in iPhone devices using Swift where source is UIButton. I created UIPopOver from UIBarButtonItem and its working fine but It's not working in case of UIButton. Can anyone suggest a better solution asap. I need to work it in iPhone device.

Nirav D
  • 71,513
  • 12
  • 161
  • 183
Srijan Kumar
  • 223
  • 1
  • 3
  • 13
  • see this http://stackoverflow.com/questions/28521583/uipopoverpresentationcontroller-on-iphone-doesnt-produce-popover – Anbu.Karthik Aug 10 '16 at 06:37

1 Answers1

1

Yes you can, but you need to implement delegate of 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)

Now implement this method of popoverPresentationController inside your ViewController

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return .None;
}
Nirav D
  • 71,513
  • 12
  • 161
  • 183