关于
Autolayouts in UIScrollView using Cirrious.FluentLayouts.Touch
设置
contentSize
属于
UIWebView
,然后让它
AtBottomOf Scrollview
.
第1轮
_artcileTextWeb.Below(view1, padding),
_artcileTextWeb.WithSameLeft(view1),
_artcileTextWeb.WithSameRight(view3),
_artcileTextWeb.Height().EqualTo(_artcileTextWeb.ScrollView.ContentSize.Height),
_artcileTextWeb.AtBottomOf(_scrollView)
但它不起作用,
ScrollView.ContentSize.Height
返回不正确的结果。
第2轮
_artcileTextWeb = new UIWebView(UIScreen.MainScreen.Bounds);
_artcileTextWeb.LoadHtmlString(text, null);
_artcileTextWeb.ScrollView.ScrollEnabled = false;
string result = _artcileTextWeb.EvaluateJavascript("document.body.offsetHeight;");
int height = Convert.ToInt32(result);
_scrollView.AddConstraints(
_artcileTextWeb.Below(view1, padding),
_artcileTextWeb.WithSameLeft(view1),
_artcileTextWeb.WithSameRight(view3),
_artcileTextWeb.Height().EqualTo(height),
_artcileTextWeb.AtBottomOf(_scrollView)
);
结果总是返回667(屏幕高度),所以我将计算转移到方法
LoadingFinished
第3轮
UIWebViewDelegate的新子类
class MyDelegate : UIWebViewDelegate
{
UIScrollView mainView;
public MyDelegate(UIScrollView view) {
mainView = view;
}
public override void LoadingFinished(UIWebView webView)
{
string result = webView.EvaluateJavascript("document.body.offsetHeight;");
mainView.AddConstraints(webView.Height().EqualTo(Convert.ToInt64(result)));
}
}
在ViewController中
_artcileTextWeb = new UIWebView(UIScreen.MainScreen.Bounds);
_artcileTextWeb.Delegate = new MyDelegate(_scrollView);
_artcileTextWeb.LoadHtmlString(text, null);
_artcileTextWeb.ScrollView.ScrollEnabled = false;
_artcileTextWeb.Below(view1, padding),
_artcileTextWeb.AtLeftOf(_scrollView), //modify this line
_artcileTextWeb.WithSameWidth(_scrollView), //modify this line
_artcileTextWeb.AtBottomOf(_scrollView)
最后,它成功了。