ios - UIAlertController popoverPresentationController 覆盖 sourceView

标签 ios ipad uialertcontroller

我正在为 UIAlertController 设置属性,如下所示:

alertController.modalPresentationStyle = .popover
alertController.popoverPresentationController?.sourceView = sourceView
alertController.popoverPresentationController?.sourceRect = sourceView.bounds

在 iPad 上显示此 alertController 会按预期显示一个弹出窗口,弹出窗口箭头的尖端恰好位于 sourceView 的中心,正如预期的那样。但是,这覆盖了我的 sourceView 的部分内容。有什么我可以做的,内容不会被覆盖吗?例如,如果箭头指向下方,则箭头尖端将位于我的 sourceView 的顶部。如果箭头指向上方,则箭头尖端将位于我的 sourceView 的底部。我可以操纵 sourceRect,但我无法提前知道箭头的方向。

最佳答案

箭头应该指向sourceRect 相对于sourceView 的外部。当您将 sourceView.bounds 作为 sourceRect 时,它应该是整个源 View 。所以不应该重叠。

在那里设置一个断点并单步执行并验证一切是否如您所愿。

关于ios - UIAlertController popoverPresentationController 覆盖 sourceView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54472990/

相关文章:

ios - 椰子足 : Library Not found

jquery - 使用jquery在touchmove上滚动事件

swift - 自iOS 13起,每个UIAlertController都会在用户响应之前自动消失

Swift - 存储 UIAlertController 文本值

swift - 在没有 UINavigationController 的情况下使用 Alert 推送 UIViewController

ios - 在内存不足的 iOS 中播放 Motion JPG 流

ios - 从可重用 Cell 出列时,自定义 CollectionViewCell 会触发什么方法?

ios - 使用 UIActivityViewController 共享多个图像

iphone - 关于 AttributeString - 将多次出现设为粗体

iphone - 这可能是一个幼稚的问题,但如何与 iPad/iPhone 的蓝牙连接?