我在左角有一个带有 UIBarButtomItem 的工具栏,标签为 Admin

ios - UIBarButtonItem 为 popoverPresentationController 提供了错误的框架-LMLPHP

我需要在点击它时显示一个弹出框,但它出现在错误的位置,它出现在屏幕的左上角:

ios - UIBarButtonItem 为 popoverPresentationController 提供了错误的框架-LMLPHP

这是打开弹出框的函数:

// this IBAction is assigned only to the Admin bar button item
@IBAction func openAdmin(sender: UIBarButtonItem) {
    let alertController = UIAlertController(title: nil, message: "Elige una opción", preferredStyle: .ActionSheet)

    // action button initializations... ... ...

    let barButtonItemSize = sender.valueForKey("view")

    alertController.popoverPresentationController?.sourceView = self.view
    alertController.popoverPresentationController?.sourceRect = barButtonItemSize!.frame

    presentViewController(alertController, animated: true, completion: nil)
}

当我触摸管理栏按钮时,我也会在控制台上收到此警告:



我究竟做错了什么?或者我需要做什么才能在管理员顶部显示弹出框?

最佳答案

代替

alertController.popoverPresentationController?.sourceView = self.view
alertController.popoverPresentationController?.sourceRect = barButtonItemSize!.frame


alertController.popoverPresentationController?.sourceView = sender
alertController.popoverPresentationController?.barButtonItem = sender

关于ios - UIBarButtonItem 为 popoverPresentationController 提供了错误的框架,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38726649/

10-11 17:37