gpt4 book ai didi

iphone - 有没有办法动态更改 View 以填充屏幕?

转载 作者:行者123 更新时间:2023-12-01 16:55:04 24 4
gpt4 key购买 nike

在我的 iOS 应用程序中,我在另一个 View 中定义了三个 Web View 。其中两个 web View 可能并不总是被使用,那么有没有办法让剩余的 View 填满屏幕的其余部分?当您使用“fill_parent”时,Android 中的等价物。

现在我正在通过改变框架来完成这一切,这真的很麻烦。

// There is no top banner, but it does use the footer
topBannerView.frame = CGRectMake(0, 0, 320, 0);
mainView.frame = CGRectMake(0, 0, 320, 400);
footerView.frame = CGRectMake(0, 400, 320, 60);

有没有办法让 mainView 在不明确设置框架的情况下使用屏幕的其余部分?

最佳答案

除了在值中进行硬编码之外,您还可以在其中放入一些代码来查看正在显示的内容的大小并从中计算您的 View 需要的大小。它可能看起来像:

if(!topBannerView.hidden)
{
topBannerHeight = topBannerView.bounds.size.height; //syntax here might be a little off, can't test code right now, but I think it's close to this
}
else
{
topBannerHeight = 0;
}

重复其他 2 个 View ,然后
topBannerView.frame = CGRectMake(0, 0, 320, topBannerHeight);
mainView.frame = CGRectMake(0, topBannerHeight, 320, mainViewHeight);
footerView.frame = CGRectMake(0, (mainViewHeight+topBannerHeight), 320, footerViewHeight);

这种方式仍然有点笨拙,但是如果您将来想调整大小,它会更好一些。

编辑:我清理了语法,现在应该是正确的。

关于iphone - 有没有办法动态更改 View 以填充屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12413073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com