我一直在尝试创建自己的代码,以及复制和粘贴示例,但我的popover似乎填满了整个屏幕。通常我的代码如下所示,但就像我说的那样,我已经尝试了至少两个其他示例(一些使用CGSizeMake(),sourceRect,sourceView),结果总是相同的。
Class TableView: UITableViewController, UIPopoverPresentationControllerDelegate {
let popover = UIViewController()
func someButton() {
popover.modalPresentationStyle = .Popover
popover.preferredContentSize = CGSize(1, 1)
let menu = popover.popoverPresentationController
menu!.delegate = self
menu!.barButtonItem = someOtherCorrectButton
self.presentViewController(popover, animated: true, completion: nil)
}
}
问题是什么?
答案 0 :(得分:0)
尝试以下代码
popover.modalPresentationStyle = .Popover
var popupHeight:CGFloat = 542
let popupWidth = 400 as CGFloat
popover.preferredContentSize = CGSizeMake(400,popupHeight)
let window = UIApplication.sharedApplication().delegate!.window!!
let screenSize: CGRect = window.bounds
var XCordinate = (screenSize.width - popupWidth) / 2
var YCordinate = (screenSize.height / 2) + 20
let menu = popover.popoverPresentationController
menu!.delegate = self
menu!.sourceView = window
menu!.sourceRect = CGRect( x: XCordinate, y: YCordinate, width: 1, height: 1)
self.presentViewController(popover, animated: true, completion: nil)
可能对你有用。