首页 > 解决方案 > 如何在使用多个 UIPopoverPresentationController allowedArrowDirections 时将首选项设置为一个箭头方向?

问题描述

我正在制作一个弹出式演示视图控制器,我需要在其中使用多个箭头方向(updown)。为了拥有多个permittedArrowDirections,我在 Swift 的 UIPopoverController 上遵循了 Set Multiple Arrow Directions。我还调整了弹出框的背景颜色,使箭头与背景调光视图融为一体。

问题是,对于几乎所有情况,我都需要使用 ,UIPopoverArrowDirection.up但对于源视图正下方没有足够空间的情况,只有UIPopoverArrowDirection.down应该使用 。但我找不到弄清楚。代码片段是:

let presentationController = .....
presentationController.sourceView = sourceView
presentationController.sourceRect = sourceView.bounds

// changing the array order doesn't help
presentationController.permittedArrowDirections = [.up, .down]

presentationController.backgroundColor = UIColor(white: 0, alpha: 0)
self.present(controller, animated: true)

为了清楚起见,我附上了当前的输出: 弹出首选箭头方向

如果有人需要跟进,可以在这里找到我尝试过的演示的源代码。

标签: iosswiftuipopoverpresentationcontroller

解决方案


推荐阅读