How to change the UIPopover anchor point? PresentFromRect is not working correctly for me.

I looked through several options, for example:

* http://blog.waynehartman.com/archive/2012/01/07/uistoryboard-on-ios-5-the-good-the-bad-and-the.aspx * UIPopoverController Anchor Position * Can I change the reference UIPopover animation point?

I am trying to show a popover for map annotation in mapview. I am currently using a workaround. I created a view in my storyboard view controller and attached my popover to that view. I move the view to the right place and then load the popover using:

(a) find the location of the annotation

CGPoint annotationPoint = [_mapView    convertCoordinate:self.selectedAnnotationView.annotation.coordinate toPointToView:_mapView];
float boxDY= annotationPoint.y;
float boxDX= annotationPoint.x;
CGRect box = CGRectMake(boxDX,boxDY,1,1);

(b) move the view (anchorView) that I created in the storyboard to the annotation area

anchorView.frame = box;

(c) popover

[annotationPopoverController presentPopoverFromRect:box inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];  

, . ?

,

+3
3

, . - Stackoverflow.

segues popover, popover.

, , , popover, segues.

, , .

popover

self.detailsPopover = [[self storyboard] instantiateViewControllerWithIdentifier:@"identifierName"];

//... config code for the popover 

UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:detailsPopover];

//... store popover view controller in an ivar

[self.annotationPopoverController presentPopoverFromRect:selectedAnnotationView.bounds inView:selectedAnnotationView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];  
+1
0
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let identifier = segue.identifier {
        switch identifier {
        case "popover":
            if let vc = segue.destination as? MyTemplateTableViewController, let ppc = vc.popoverPresentationController {
                ppc.permittedArrowDirections = .up
                ppc.delegate = self
// set the sourceRect and sourceView to move the anchor point
                ppc.sourceRect = ((sender as? UITextField)?.frame)!
                ppc.sourceView = sender as? UITextField

            }
            break
        default:
            break

        }
        }
    }
0
source

All Articles