Is it possible to move a UIPopovercontroller around the screen once its al开发者_运维知识库ready been presented?
I have a small view in my app that can move slightly, and I would like a UIPopoverController to move around with it without having to re-present the UIPopoverController every time it moves. Is this possible?As of iOS 9, "UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController."
Use the following to present a popover. You may be able to change the values of sourceRect and sourceView but this isn't intended API behavior.
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:^{
}];
Instead, I suggest keeping a reference to the view controller presented with the popover, dismiss the popover and re-present.
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:^{
}];
}];
You can re-call presentPopoverFromRect.
See http://developer.apple.com/library/ios/#qa/qa1694/_index.html
No you can't. This is no method to do that.
pover presentPopoverFromRect:
was mentioned in the comments, but notice the
present
you cannot represent without redrawing.
You can track the users touches around the screen, and use presentPopoverFromRect:
to reshow the popover.
精彩评论