0

我最近开始遇到一个问题,弹出框控制器有时会出现在错误的角落。当它正常工作时,弹出源是右上角的一个按钮。这是大多数时候发生的事情。现在,当我从特定路线“过快”登陆此页面时,弹出框会显示在左上角。

另一件奇怪的事情是,当加载被人为延迟时(比如我为调试设置断点时),弹出框会正确显示。

由于这似乎是一个时间问题,我尝试将导航配置从 viewDidLoad 移动到 viewDidAppear,但这不起作用。

这个函数是从 viewDidLoad 调用的:

func configureNav() {

        if canAddDoc == true {
            let customButton = UIButton(type: .system)
            customButton.setImage(with: .add, tintColor: UIColor.white, imageEdgeInsets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
            customButton.addTarget(self, action: #selector(showAddDocSheet), for: .touchUpInside)
            addButton = UIBarButtonItem(customView: customButton)
        }

        shareButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.action,
                                      target: self,
                                      action: #selector(shareButtonPressed))
        navigationItem.rightBarButtonItems = (addButton == nil) ? [shareButton!] : [shareButton!, addButton!]

        @objc func showAddDocSheet() {
            guard let addButton = addButton else { return }
            self.displayActionSheet(sourceButton: addButton)
        }

    }

func displayActionSheet(sourceButton: UIBarButtonItem) {

    let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

     //Action sheet code goes here


    if let popoverController = actionSheet.popoverPresentationController {
        popoverController.barButtonItem = sourceButton
        popoverController.sourceView = sourceButton.customView
        popoverController.permittedArrowDirections = .up
    }

    self.present(actionSheet, animated: true, completion: nil)

}
4

1 回答 1

0

这听起来可能是一个奇怪的解决方案,但我之前也发生过类似的事情,并且在呈现 VC 时将动画设置为 false 时得到了解决,

self.present(actionSheet, animated: false, completion: nil)
于 2020-06-09T20:54:42.663 回答