7

我的UIBarButtonItem导航控制器上有一个图像:

    infoItem = UIBarButtonItem(image: infoImage,
                               style: .plain, 
                               target: self,
                               action: #selector(infoAction))
    navigationItem.rightBarButtonItem = infoItem

当点击我做:

@objc func infoAction()
{
    let popoverContentController = InfoViewController()

    popoverContentController.preferredContentSize = CGSize(width: 300, height: 300)
    popoverContentController.modalPresentationStyle = .popover
    popoverContentController.popoverPresentationController?.delegate = self

    self.present(popoverContentController, animated: true, completion: nil)
}

然后调用UIPopoverPresentationControllerDelegate函数:

func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController)
{
    popoverPresentationController.permittedArrowDirections = .any
    popoverPresentationController.barButtonItem = infoItem  <<=====
}

func adaptivePresentationStyle(for controller: UIPresentationController,
                               traitCollection: UITraitCollection) -> UIModalPresentationStyle
{
    return .none
}

我在那里<<=====设置了barButtonItem. 我现在希望弹出箭头指向该项目的中心。但它没有:

箭头从中心向右

查看视图层次结构(下图),我的图像在矩形条形按钮中水平居中。它根本不在左侧,这可以解释弹出箭头未对齐的原因。

查看层次结构

任何想法我在这里缺少什么,或者如何纠正?

4

0 回答 0