OStack程序员社区-中国程序员成长平台

标题: ios - AutoLayout 约束和 UIPopoverPresentationController [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 17:07
标题: ios - AutoLayout 约束和 UIPopoverPresentationController

AutoLayout 似乎每一步都在与 View 大小作斗争。

我有一个用于用户输入的 View Controller ,而 AutoLayout 似乎坚定不移地决定让我的 View 高 667 像素。

我玩过许多布局设置变体、许多内容拥抱和抗压缩组合,无论我做什么,AutoLayout 都能找到将 View 拉伸(stretch)到 667 像素高的方法。

我使用 Reveal,一个显示布局框架、约束等的应用程序 (revealapp.com) 它向我展示了 UIPopoverPresentationController 正在添加自己的自动调整大小约束。

这是我的 View 在呈现时的大致外观...

enter image description here

请注意,即使我将“接受”UIButton 设置为 30 像素高和 1000 优先级,AutoLayout 仍在拉伸(stretch)它以满足其奇怪的 667 像素高要求。

当我运行应用程序时,我的弹出框看起来是这样的......

enter image description here

当我让 Reveal 检查正在运行的应用程序并将其缩小到弹出框时,这就是 Reveal 显示的内容...

enter image description here

enter image description here

注意 UIPopoverPresentationController 本身有这些约束。

如何控制 UIPopoverPresentationController 所设置的约束??



Best Answer-推荐答案


尝试使用 ptions:attributes:context:" rel="noreferrer noopener nofollow">boundingRectWithSize(_ptions:attributes:context NSString 来确定标签的高度。

完成此操作后,您可以通过添加标签创建的任何额外高度来预测弹出框的大小。您可以使用它来设置您正在呈现的 View Controller 的 preferredContentSize 属性。

关于ios - AutoLayout 约束和 UIPopoverPresentationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37999365/






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4