UIPopoverController 可以在屏幕上移动吗?

发布于 2024-11-06 01:50:23 字数 146 浏览 0 评论 0原文

一旦 UIPopovercontroller 已经呈现,是否可以在屏幕上移动它?
我的应用程序中有一个可以轻微移动的小视图,我希望 UIPopoverController 能够随其移动,而不必在每次移动时重新呈现 UIPopoverController。这可能吗?

Is it possible to move a UIPopovercontroller around the screen once its already 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

笑,眼淚并存 2024-11-13 01:50:23

从 iOS 9 开始,“UIPopoverController 已被弃用。Popover 现在被实现为 UIViewController 演示文稿。使用 UIModalPresentationPopover 和 UIPopoverPresentationController 的模式演示样式。”

使用以下内容呈现弹出窗口。您也许可以更改 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:^{

    }];

相反,我建议保留对随弹出窗口呈现的视图控制器的引用,关闭弹出窗口并重新呈现。

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:^{

    }];
}];

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:^{

    }];
}];
呢古 2024-11-13 01:50:23

您可以重新调用presentPopoverFromRect。

请参阅 http://developer.apple.com/library/ios/# qa/qa1694/_index.html

You can re-call presentPopoverFromRect.

See http://developer.apple.com/library/ios/#qa/qa1694/_index.html

想念有你 2024-11-13 01:50:23

不,你不能。这是没有办法做到这一点的。

pover presentPopoverFromRect:

评论中提到了,但请注意

现在

如果不重新绘制就无法表示。

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.

瞳孔里扚悲伤 2024-11-13 01:50:23

您可以跟踪用户在屏幕上的触摸,并使用 presentPopoverFromRect: 重新显示弹出窗口。

You can track the users touches around the screen, and use presentPopoverFromRect: to reshow the popover.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文