单击导航栏时 UIPopoverController 不会关闭

发布于 2024-11-09 13:14:57 字数 160 浏览 7 评论 0原文

当点击 rightBarButton 时,会出现一个 UIPopoverController。

问题是:当单击导航栏时,此 UIPopoverController 不会关闭。

为什么?并且有办法解决吗? 我尝试过搜索,但找不到任何与此相关的信息。

提前致谢。

When clicking on a rightBarButton, a UIPopoverController will present.

The problem is: when clicking on the NavigationBar, this UIPopoverController does not dismiss.

Why? And is there a way to resolve it?
I have tried to search, but can't find anything about this.

Thanks in advance.

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

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

发布评论

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

评论(6

白云悠悠 2024-11-16 13:14:57

UIPopoverController 似乎在呈现导航栏时将其添加到其 passthroughViews 数组中。我能够通过在呈现弹出窗口后立即将 passthroughViews 重新设置为空数组来解决该问题。

UIPopoverController seems to add the navigation bar to its passthroughViews array when it is presented. I was able to solve the problem by re-setting passthroughViews to an empty array immediately after presenting the popover.

勿忘初心 2024-11-16 13:14:57

从栏按钮启动时,您可以简单地执行此操作

[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popoverController setPassthroughViews:nil];

When launching from a bar button you can simply do this

[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popoverController setPassthroughViews:nil];
疾风者 2024-11-16 13:14:57

导航栏上的项目将自动添加到 popoverViewController 的 passthroughViews 中。它发生在弹出窗口出现后。所以之后你需要清除 passthroughViews 。

对于iOS 8,我们可以从UIViewController.popoverPresentationController获取popoverController,在此之前,我们可以从UIStoryboardPopoverSegue获取popoverController。

在您的视图控制器中,将视图控制器呈现为弹出窗口。

var popoverController: UIPopoverController?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Before IOS8, we need to get reference of popOverController from UIStoryboardPopoverSegue
    if (!self.respondsToSelector(Selector("popoverPresentationController"))) {
        if let popoverController = (segue as? UIStoryboardPopoverSegue)?.popoverController {
            let menuViewController = segue.destinationViewController as AIMSMenuTableViewController
            menuViewController.popoverController = popoverController
        }
    }
}

在您的视图控制器中,它显示为弹出窗口。

var popoverController: UIPopoverController? 

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    // Set passthroughViews to nil make tapping other navigation bar button
    // dismiss presenting popoverController
    if (self.respondsToSelector(Selector("popoverPresentationController"))) {
        self.popoverPresentationController?.passthroughViews = nil
    } else {
        // For iOS8-pre version, we need to pass popoverController reference from segue
        self.popoverController?.passthroughViews = nil
    }
}

Items on your navigation bar will be automatically added to popoverViewController's passthroughViews. It happens after the popover shows up. So you need to clear passthroughViews after that.

And for iOS 8, we can get popoverController from UIViewController.popoverPresentationController, before that, we can get popoverController from UIStoryboardPopoverSegue.

In your view controller presents a view controller as popover.

var popoverController: UIPopoverController?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Before IOS8, we need to get reference of popOverController from UIStoryboardPopoverSegue
    if (!self.respondsToSelector(Selector("popoverPresentationController"))) {
        if let popoverController = (segue as? UIStoryboardPopoverSegue)?.popoverController {
            let menuViewController = segue.destinationViewController as AIMSMenuTableViewController
            menuViewController.popoverController = popoverController
        }
    }
}

In your view controller that is presented as popover.

var popoverController: UIPopoverController? 

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    // Set passthroughViews to nil make tapping other navigation bar button
    // dismiss presenting popoverController
    if (self.respondsToSelector(Selector("popoverPresentationController"))) {
        self.popoverPresentationController?.passthroughViews = nil
    } else {
        // For iOS8-pre version, we need to pass popoverController reference from segue
        self.popoverController?.passthroughViews = nil
    }
}
纵情客 2024-11-16 13:14:57

UIPopoverController 的文档 指出:

显示时,点击外部
弹出窗口导致弹出窗口
自动解雇。为了允许
用户与指定的交互
视图而不是关闭弹出窗口,您
可以将一个或多个视图分配给
passthroughViews 属性。里面有水龙头
弹出窗口没有
自动导致弹出窗口
被解雇了。你的看法和看法
控制器代码必须处理操作
以及弹出框内的事件
明确并调用
missPopoverAnimated:方法为
需要。

当从栏按钮项呈现弹出窗口时,导航栏将添加为 passthroughViews 之一。

也许尝试在弹出窗口控制器上设置一个空数组作为 passthroughViews 属性。

The documentation for UIPopoverController states:

When displayed, taps outside of the
popover window cause the popover to be
dismissed automatically. To allow the
user to interact with the specified
views and not dismiss the popover, you
can assign one or more views to the
passthroughViews property. Taps inside
the popover window do not
automatically cause the popover to be
dismissed. Your view and view
controller code must handle actions
and events inside the popover
explicitly and call the
dismissPopoverAnimated: method as
needed.

The navigation bar is added as one of the passthroughViews when the popover is presented from a bar button item.

Perhaps try settings an empty array as the passthroughViews property on your popover controller.

黯淡〆 2024-11-16 13:14:57

您将此鳕鱼放在任何其他操作上或完成选择后或在弹出窗口中提供一些关闭按钮并完成 uy yhing,

[popOverControllerObj dismissPopoverAnimated:YES];

You put this cod on any other action or After completing the selection or provide some close button in the popover and accomplish uy yhing,

[popOverControllerObj dismissPopoverAnimated:YES];
心头的小情儿 2024-11-16 13:14:57

据我所知,这是预期的行为。 iBooks 中书架上的弹出窗口的行为如下。呈现弹出窗口时保留对弹出窗口的引用,然后在点击导航栏中的任何按钮时将其关闭。

This is expected behavior as far as I can tell. The popover on the bookshelf in iBooks behaves like this. Retain a reference to the popover when you present it, and then dismiss it if any of the buttons in the navigation bar are tapped.

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