首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Xcode,Swift:如何使弹出框居中

Xcode,Swift:如何使弹出框居中
EN

Stack Overflow用户
提问于 2016-05-13 03:29:19
回答 3查看 3K关注 0票数 2

链接到我的github帐户的文件,只需下载压缩:https://github.com/jzhang172/modalTest

当我点击" popover“链接时,我想把popover放在屏幕中央。

我尝试引用一些堆栈溢出问题,例如:how to center a popoverview in swift

但没那么走运。我是swift的新手,我只使用swift,而不是objective C。

我看到的屏幕截图:

EN

回答 3

Stack Overflow用户

发布于 2016-05-23 23:56:41

替换

代码语言:javascript
运行
复制
controller?.sourceRect = CGRectMake(0.0, self.view.layer.bounds.height * 0.5,0.0,0.0)

使用

代码语言:javascript
运行
复制
controller?.sourceRect = CGRectMake(self.view.layer.bounds.width * 0.5, self.view.layer.bounds.height * 0.5,0.0,0.0)

将使弹出内容水平和垂直居中。

票数 2
EN

Stack Overflow用户

发布于 2016-05-13 04:00:04

您可以使用下面的代码在视图中居中显示UIPopover

代码语言:javascript
运行
复制
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)
票数 1
EN

Stack Overflow用户

发布于 2017-02-09 17:24:29

Swift 3:

代码语言:javascript
运行
复制
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)
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37195856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档