UIBarButtonItem 给我错误的 popoverPresentationController 框架
UIBarButtonItem gives me wrong frame for popoverPresentationController
我有一个工具栏,左上角有一个 UIBarButtomItem
,标签为 Admin
我需要在点击它时显示一个弹出窗口,但它出现在错误的位置,它出现在屏幕的左上角:
这是打开弹窗的函数:
// 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)
}
当我触摸管理栏按钮时,我还在控制台上收到此警告:
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates
我做错了什么?或者我需要做什么才能在管理员顶部显示弹出窗口?
替换
alertController.popoverPresentationController?.sourceView = self.view
alertController.popoverPresentationController?.sourceRect = barButtonItemSize!.frame
和
alertController.popoverPresentationController?.sourceView = sender
alertController.popoverPresentationController?.barButtonItem = sender
我有一个工具栏,左上角有一个 UIBarButtomItem
,标签为 Admin
我需要在点击它时显示一个弹出窗口,但它出现在错误的位置,它出现在屏幕的左上角:
这是打开弹窗的函数:
// 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)
}
当我触摸管理栏按钮时,我还在控制台上收到此警告:
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates
我做错了什么?或者我需要做什么才能在管理员顶部显示弹出窗口?
替换
alertController.popoverPresentationController?.sourceView = self.view
alertController.popoverPresentationController?.sourceRect = barButtonItemSize!.frame
和
alertController.popoverPresentationController?.sourceView = sender
alertController.popoverPresentationController?.barButtonItem = sender