Auto view layout change

Is there a way to automatically change an element (e.g. WebView) when a hidden element (UIImageView) is hidden?

I have a regular UIView with a WebView in it showing HTML, but in some cases there is a need for an image above this. Therefore, I put the image over the WebView, but I would like the web view to also occupy the ImageView space when it is not, otherwise there is a white panel.

Another option is to place it over Webview, but I don’t think that in any case, the text will flow around the image.

Anyone have suggestions for neat solutions? Thanks for the million!

+4
source share
3 answers

A convenient trick I found out is to rely on CGRectDivide() - of course, you have to write your own layoutSubviews method, but it's not too complicated:

 -(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 ; } 
+2
source

Why does such a problem simply resize your WebView in the same method that shows or hides the image?

By the way, Cocoa Autolayout was introduced for OSX Lion. IOS 6 is currently under NDA, but if you have a developer account, look, maybe there is something like this.

0
source

Check out the CSLinearLayoutView . It is trying to simulate Android LinearLayout and RelativeLayout and should be able to simplify dynamic resizing / moving views.

0
source

Source: https://habr.com/ru/post/1338424/


All Articles