Can a UIPopoverController be moved around the screen?

Is it possible to move the UIPopovercontroller around the screen once it has already been presented?
 I have a little idea in my application that can move a little, and I would like the UIPopoverController to move with it, without having to rethink the UIPopoverController every time it moves. Is it possible?

+5
source share
4 answers

Like iOS 9, "UIPopoverController is deprecated. Travel companions are now implemented as UIViewController presentations. Use the modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController."

, popover. sourceRect sourceView, API.

    DetailViewController *detailVC = self.detailViewController;
    detailVC.preferredContentSize = CGSizeMake(420, 92);
    detailVC.modalPresentationStyle = UIModalPresentationPopover;


    UIPopoverPresentationController *presController = detailVC.popoverPresentationController;
    if (presController) {
        presController.delegate = detailVC;
        presController.barButtonItem = self.detailButton;
        presController.sourceRect = self.view.frame;
        presController.sourceView = self.view;
        presController.permittedArrowDirections = UIPopoverArrowDirectionAny;
    }

    [self presentViewController: detailVC animated:YES completion:^{

    }];

, popover, popover .

DetailViewController *detailVC = self.detailViewController;
[self dismissViewControllerAnimated:NO completion:^{

    UIPopoverPresentationController *presController = detailVC.popoverPresentationController;
    if (presController) {
        presController.delegate = detailVC;
        presController.barButtonItem = self.detailButton;
        presController.sourceRect = self.view.frame; //Update frame
        presController.sourceView = self.view;
        presController.permittedArrowDirections = UIPopoverArrowDirectionAny;
    }

    [self presentViewController: detailVC animated:NO completion:^{

    }];
}];
+1

, . .

pover presentPopoverFromRect:

,

.

0

, , presentPopoverFromRect:, .

0

All Articles