【发布时间】:2018-04-07 03:54:13
【问题描述】:
在 iPhone 8 Plus 上,每次用户触摸视图内部时(例如当用户触摸视图控制器中的按钮时),弹出视图控制器都会关闭,而当用户触摸视图外部时(当我们期望它解雇)。在针对 iPhone 6s 和几台 iPad 进行测试时,该应用的行为符合预期。
弹出框是使用以下 Swift 代码以编程方式创建的:
let selectionViewController = SelectionTableViewController()
selectionViewController.modalPresentationStyle = .popover
selectionViewController.preferredContentSize = CGSize(width: 200, height: 300)
let popoverViewController = selectionViewController.popoverPresentationController
popoverViewController?.permittedArrowDirections = UIPopoverArrowDirection.up
popoverViewController?.delegate = self
popoverViewController?.sourceView = self.titleView
popoverViewController?.sourceRect = self.titleView.bounds
self.present(selectionViewController, animated: true, completion: nil)
此外,自适应演示样式进行了调整,以在 iPhone 上与 iPad 保持一致的行为:
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}
编辑: 我添加了一个简化版本的应用程序,它将问题重新创建到 github: https://github.com/Brandogs/PopoverIssue
【问题讨论】:
-
您的
sourceRect不正确(这可能不是问题的原因,但需要修复) -
@matt 触摸弹出框内的任意位置(按钮、表格视图单元格、空白区域)将导致弹出框关闭。触摸外面的任何地方都不会解散。感谢 sourceRect 提示!
-
@matt 我更新了 sourceRect 以引用 self.titleView.bounds。问题仍然存在,但该代码仍然很奇怪。再次感谢您指出这一点。
-
@matt 弹出视图控制器堆叠在其他视图和导航控制器后面,我认为这有点奇怪,但这可能是正常的。否则,所有视图位置和类似的一切看起来都很正常。是的,我认为可能是运行时也不理解弹出框,但似乎如果是这种情况,就会有一个不会关闭弹出框的错位矩形。相反,它是弹出框之外的整个区域,就好像正常行为被某种方式翻转了一样。
-
@matt 我上传了一个简化的项目,将问题重新创建到 GitHub 并将链接放在原始帖子中。