iOS: iOS13中popover边框显示问题

iOS: Problem of display the popover border in the iOS13

我显示的弹窗现在显示不正确。箭头一侧缺少一条线。我们可以检查箭头末端是否有一小块黑色。我觉得里面有个view太长了

显示弹出窗口的代码:

   _popoverController = UIPopoverController(contentViewController: navController)
   _popoverController?.delegate = self

   let rect = slotCollectionView.cellForItem(at: indexPath)!.frame
   self._popoverController?.backgroundColor = UIColor.init(rgb: Int(quaternaryColorHexa))
   self._popoverController?.present (from: rect, in: self.slotCollectionView, permittedArrowDirections: UIPopoverArrowDirection.any, animated: true) 

初始化弹出窗口的代码:

override func viewDidLoad()
{
    super.viewDidLoad()

    self.preferredContentSize = contentSize()
    self.navigationController!.preferredContentSize = self.preferredContentSize;

    peopleTableView.isScrollEnabled = true
    peopleTableView.bounces = true
    peopleTableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
    peopleTableView.tableFooterView?.isHidden = true
    peopleTableView.backgroundColor = UIColor.init(rgb: Int(quinquenaryColorHexa))

    self.view.backgroundColor = UIColor.init(rgb: Int(quinquenaryColorHexa))
    self.view.layer.cornerRadius = 13.0
    self.view.layer.borderWidth = 1.5
    self.view.layer.borderColor = UIColor.init(rgb: Int(quaternaryColorHexa)).cgColor 

iOS12显示:

iOS13 显示:

this answer 中所述,UIPopover 在其内容视图中包含箭头是 iOS 13 的一项新功能。您应该使用安全区域来正确应对此更改。

您无法使用安全区域对此更改作出反应。我的感觉是,这是 iOS 13 中的错误,我将解释原因...

当您遇到使用 UIPopoverArrowDirectionAny 的情况时,您会发现问题仅在箭头位于弹出框的顶部或左侧时存在,而不是当箭头出现在弹出框的右侧或底部时。如果您在代码中进行调整以进行补偿,那么如果您使用 UIPopoverArrowDirectionUp 或 UIPopoverArrowDirectionLeft 它将起作用,但在使用 UIPopoverArrowDirectionAny 并且弹出窗口出现在目标矩形的上方或右侧时将无法使用该调整正确显示。

我认为这是 iOS13 版本中的一个 iOS 错误,我建议您使用那个 git 项目来制作自己的弹出窗口:
DDPopoverBackgroundView

并使用它来显示弹出窗口:

       // Popover
       _popoverController = UIPopoverController(contentViewController: navController)
       _popoverController?.delegate = self

       let rect = slotCollectionView.cellForItem(at: indexPath)!.frame

       self._popoverController!.contentSize = CGSize(width: 350, height: 600)

       self._popoverController!.backgroundViewClass = DDPopoverBackgroundView.self
       self._popoverController!.backgroundColor = UIColor.init(rgb: Int(quaternaryColorHexa)) //arrow color

       OperationQueue.main.addOperation({
           self._popoverController?.present(from: rect, in: self.slotCollectionView, permittedArrowDirections: UIPopoverArrowDirection.any, animated: true)
       })

享受吧! ;-)

我遇到了同样的问题。我的解决方案如下:

class MyPopoverViewController: UIViewController {
    override func viewWillAppear(_ animated: Bool) {
        let borderColor = UIColor.black
        let borderWidth = CGFloat(1.5)
        let cornerRadius = CGFloat(13)
        let extensionWidth = CGFloat(20)

        if #available(iOS 13, *), let superview = self.view.superview {
            let guide = self.view.safeAreaLayoutGuide
            let borderView = UIView()
            borderView.isUserInteractionEnabled = false
            borderView.backgroundColor = UIColor.clear
            borderView.layer.borderWidth = borderWidth + extensionWidth
            borderView.layer.cornerRadius = cornerRadius + extensionWidth
            borderView.layer.borderColor = borderColor.cgColor
            borderView.translatesAutoresizingMaskIntoConstraints = false
            superview.addSubview(borderView)
            NSLayoutConstraint.activate([
                borderView.leftAnchor.constraint(equalTo: guide.leftAnchor, constant: -extensionWidth),
                borderView.topAnchor.constraint(equalTo: guide.topAnchor, constant: -extensionWidth),
                borderView.bottomAnchor.constraint(equalTo: guide.bottomAnchor, constant: extensionWidth),
                borderView.rightAnchor.constraint(equalTo: guide.rightAnchor, constant: extensionWidth)
            ])
        } else {
            self.view.layer.borderWidth = borderWidth
            self.view.layer.cornerRadius = cornerRadius
            self.view.layer.borderColor = borderColor.cgColor
            self.view.clipsToBounds = true
            self.popoverPresentationController?.backgroundColor = borderColor
        }
    }
}