如何在 UIPopoverController 之上添加视图

发布于 2024-08-28 08:45:01 字数 375 浏览 11 评论 0原文

我有一个 iPad 应用程序,其中有一个“抽屉”表显示在弹出窗口中。用户可以点击并按住抽屉中的某个项目,将该项目从抽屉中拖出并拖入我的主视图中。那部分工作正常;不幸的是,被拖动的视图出现在弹出窗口下方,并且太小而无法看到,直到从其下方拖出为止。如果我将视图添加为弹出窗口中的视图控制器的子视图,它会被弹出窗口的框架剪切,并且因为我无法访问 UIPopoverController 的视图,我无法禁用其图层的 masksToBounds - 无论如何,这可能不是一个好主意。我怀疑我可以使用一个具有高 windowLevel 值的附加 UIWindow 来强制拖动的视图出现在弹出窗口的顶部,但这似乎有点矫枉过正。有更好的解决方案吗?

I've got an iPad app with a “drawer” table displayed in a popover. The user can tap-and-hold on an item in the drawer to drag that item out of it and into my main view. That part works fine; unfortunately, the view being dragged appears under the popover, and is too small to be visible until it's dragged out from underneath it. If I add the view as a subview of the view controller in the popover, it gets clipped by the popover's frame, and as I can't access the UIPopoverController's view, I can't disable its layer's masksToBounds—and that probably wouldn't be a great idea anyway. I suspect that I could use an additional UIWindow with a high windowLevel value to force the dragged view to appear on top of the popover, but this seems like overkill. Is there a better solution?

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

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

发布评论

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

评论(2

再见回来 2024-09-04 08:45:01

知道了。 UIWindow 工作正常。代码:

// when drag starts
draggingView = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,100,100)];
draggingView.windowLevel = UIWindowLevelAlert;
draggingView.center = [gestureRecognizer locationInView:self.view.window];
[draggingView makeKeyAndVisible];

// when drag ends
[draggingView release];
draggingView = nil;

Got it. UIWindow works fine. Code:

// when drag starts
draggingView = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,100,100)];
draggingView.windowLevel = UIWindowLevelAlert;
draggingView.center = [gestureRecognizer locationInView:self.view.window];
[draggingView makeKeyAndVisible];

// when drag ends
[draggingView release];
draggingView = nil;
隱形的亼 2024-09-04 08:45:01

添加 Swift 版本:

    let windows: [UIWindow] = UIApplication.shared.windows
    let firstWindow: UIWindow = windows[0]

    firstWindow.addSubview(loadingView)
    firstWindow.bringSubview(toFront: loadingView)

编辑管理员:感谢您的审查 - 重复删除我的其他答案 如何在 UIPopoverController 上显示 UIView

Adding the Swift Version:

    let windows: [UIWindow] = UIApplication.shared.windows
    let firstWindow: UIWindow = windows[0]

    firstWindow.addSubview(loadingView)
    firstWindow.bringSubview(toFront: loadingView)

EDIT to admin: thanks for the review – deleted my other answer in duplicate How to show a UIView OVER a UIPopoverController

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