ios - 如何指定弹出 Controller 的箭头指向的位置

标签 ios uipopovercontroller uialertcontroller

众所周知,为了使用 preferredStyle: .actionSheet 呈现 UIAlertController,使用下一个代码设置 anchor 是一个很好的做法:

 popover.sourceView = view
 popover.sourceRect = view.bounds

在我的例子中, View 是 UIImageView,它的大小是 44x44,但是它的图像(三个垂直点)非常细(它的大小是 4x24)。所以 View 大部分是透明的。结果,弹出窗口“指向”空白区域。 (请注意,我使用红色来显示完全透明的区域)

enter image description here

理想情况下,弹出窗口的箭头应指向中央的白点。但我不知道如何实现它。我尝试修改 sourceRect 如下:

popover.sourceRect = CGRect(x: view.bounds.midX - 1,
                            y: view.bounds.midY - 1,
                            width: 2,
                            height: 2)

但由于某种原因它指向顶部的白点:

enter image description here

如何让它指向所需的点?

最佳答案

sourceRect 对我有用,我只是使用 y 坐标定位箭头,它对我有用。

popover.sourceRect =  CGRect(x: 0, y: yourPosition, width: 0, height: 0)

你也可以看看this .

关于ios - 如何指定弹出 Controller 的箭头指向的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50489288/

相关文章:

ios - iPad SplitViewController 以编程方式显示 Popover

ios - 在 swift 中显示 alertController 中的 textField

ios 8 Storyboard搜索栏太宽

ios - 如何让plist中的特定项目显示在tableView中

ios - 作为 willActivate 的一部分更新界面时的奇怪行为

ios - 无法确定弹出箭头方向

ios - 导航后无法删除 subview Controller

ios - 在应用程序进入后台之前允许用户输入

ios - 当用户使用 swift 键入时,限制 UIAlertController 中文本字段的输入?

ios - 从命令行自动编辑 Google 电子表格