I am currently working on an app that requieres the user profiles to be shown as a pop-over when the user picture is pressed. I managed to get this behaviour using UIPopoverPresentationControllerDelegate but I would like your help entering this pop-over in the middle of the screen.
My code looks like:
func presentProfile(sender: UIButton){
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("profileVC") as! ProfileViewController
vc.profilePicture = (self.contentIdToImage[content.hostId as! String]?.image)!
vc.modalPresentationStyle = UIModalPresentationStyle.Popover
let height = self.view.bounds.size.height
let width = self.view.bounds.size.width
vc.preferredContentSize = CGSizeMake(width * 0.8, height * 0.8)
if let presentationController = vc.popoverPresentationController {
presentationController.delegate = self
presentationController.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
presentationController.sourceView = sender
self.presentViewController(vc, animated: true, completion: nil)
}
}
Thank you
Edit:
Based on the first answer I received I started playing around with CGRect and I think the desired behaviour can be achieved using the "sourceRect" property of the UIPopoverPresentationController but I have not figure it out.