Dynamic UIView height with auto layout in iOS 6

后端 未结 2 1237
清歌不尽
清歌不尽 2020-12-12 16:12

For the last couple of days I am trying to accomplish a fairly simple (at least it should be) layout using auto layout constraints, but without success.

My view

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 16:33

    You might need a delay before updating webview content size. And masonry is useful for autolayout usage.

    -(void)webViewDidFinishLoad:(UIWebView *)webview{
        [self performSelector:@selector(checkContentOnDelay:) withObject:webview afterDelay:0.001];
    }
    
    -(void)checkContentOnDelay:(UIWebView *)webview{
        CGSize contentSize = webview.scrollView.contentSize;
        if (contentSize.height > 2) {
            [webview updateConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(contentSize.height);
            }];
        }else{
            [self performSelector:@selector(checkContentOnDelay:) withObject:webview afterDelay:0.01];
        }
    }
    

提交回复
热议问题