Any way to set position of UIPopoverPresentationController?

I have a UIPopoverPresentationController which is triggered by a BarButtonItem. I understand how to set the size of the popover using preferredContentSize (although getting it to change with rotation seems iffy) -- but is there any way to finesse the position of the thing? I want it to appear about 50 pixels to the right of where it shows up, so that I can see another interface element.


I would have thought that the popoverLayoutMargins property would be useful for this - but I can't get that to do anything. It seems to just ignore it.


Anyone know?

Thanks!

Bob

That seems possible with popoverPresentationController?.sourceRect

h ttps://stackoverflow.com/questions/33267138/popover-change-position-starting-point-origin-location-ios9

I think that is just to define the area of the source (trigger) view -- ie where the arrow points.

Here is a case where I use it :


        if isaPad {     // To display alert as popover for iPad
            if let ppc = alertController.popoverPresentationController {
                if let cell = tableView.cellForRowAtIndexPath(indexPath) {
                    ppc.sourceView = cell as UIView
                    ppc.sourceRect = (cell as UIView).bounds
                }
            }


If I add at the end :

ppc.sourceRect.origin.y += 50

Then the popover moves 50 to the bottom.

Don't forget to set ppc.sourceView , likeky self.view


ppc.sourceView = self.view

Yes but doesn't it move the arrow too then? I need my arrow to keep pointing to the button, which doesn't move. It's just the big balloon shape that I want to adjust.

Yes, it does move the arrow as well


I tried to change the height of the height,


                   ppc.sourceRect.size.height += 250

but that moves the origin as well.


So I tried to change origin back, returns to original presentaation

                    ppc.sourceRect.size.height += 250
                    ppc.sourceRect.origin.y -= 250


In fact, it seems the height is computed depending on how much information you display in the alert.

Probably different if you have a custom window to present as popover ; in that case, changing the sourceRect will move where you want.

Any way to set position of UIPopoverPresentationController?
 
 
Q