gpt4 book ai didi

iphone - 自动更改 View 的布局

转载 作者:行者123 更新时间:2023-12-03 19:19:35 25 4
gpt4 key购买 nike

有没有办法在附近的元素(UIImageView)隐藏时自动调整元素(例如WebView)的大小?

我有一个普通的 UIView,其中有一个显示 HTML 的 WebView,但在某些情况下需要在其上方添加图像。因此,我将图像放在 WebView 上方,但希望 WebView 在 ImageView 不存在时也占据 ImageView 的空间,否则会出现一个白条。

另一种选择是将其放置在 Webview 上,但我认为无论如何都无法让文本围绕图像流动。

有人对整洁的解决方案有任何建议吗?提前一百万致谢!

最佳答案

我学到的一个方便的技巧是依赖 CGRectDivide() - 当然,您必须编写自己的 layoutSubviews 方法,但这并不太困难:

-(void)layoutSubviews
{
CGRect bounds = self.bounds ;
if ( !self.imageView.hidden )
{
CGRect slice ;
CGRectDivide( bounds, & slice, & bounds, IMAGE_VIEW_HEIGHT, CGRectMinYEdge ) ;
self.imageView.frame = slice ;
}

// bounds here contains the remaining layout space with or without the image view
self.webView.frame = bounds ;
}

关于iphone - 自动更改 View 的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4898236/

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