链接到我的github帐户的文件,只需下载压缩:https://github.com/jzhang172/modalTest
当我点击" popover“链接时,我想把popover放在屏幕中央。
我尝试引用一些堆栈溢出问题,例如:how to center a popoverview in swift
但没那么走运。我是swift的新手,我只使用swift,而不是objective C。
我看到的屏幕截图:

发布于 2016-05-23 23:56:41
替换
controller?.sourceRect = CGRectMake(0.0, self.view.layer.bounds.height * 0.5,0.0,0.0)使用
controller?.sourceRect = CGRectMake(self.view.layer.bounds.width * 0.5, self.view.layer.bounds.height * 0.5,0.0,0.0)将使弹出内容水平和垂直居中。
发布于 2016-05-13 04:00:04
您可以使用下面的代码在视图中居中显示UIPopover。
let controller = vc.popoverPresentationController
controller?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
controller?.sourceView = self.view
controller?.sourceRect = CGRectMake(0.0, self.view.layer.bounds.height * 0.5,0.0,0.0)
vc.preferredContentSize=CGSize(width: 400, height: 200)发布于 2017-02-09 17:24:29
Swift 3:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let popoverPresentationController = segue.destination.popoverPresentationController {
let controller = popoverPresentationController
controller.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
controller.sourceView = self.view
controller.sourceRect = CGRect(x: UIScreen.main.bounds.width * 0.5 - 200, y: UIScreen.main.bounds.height * 0.5 - 100, width: 400, height: 200)
segue.destination.preferredContentSize=CGSize(width: 400, height: 200)
}
}https://stackoverflow.com/questions/37195856
复制相似问题