我正面临一个有趣的问题。我从我在UIWebView中显示的Web服务获取HTML数据,并且当用户点击链接时我想在Safari中打开超链接。
我所使用的代码非常适合在Web View中立即可见的任何链接。我有一个关于视图的滚动和可见区域下面的链接(即我必须滚动到的链接)在我点击它们时不起作用。
请注意,我正在使用如下逻辑禁用WebView中的所有滚动条:
DescriptionWebView = new UIWebView(new RectangleF(0, separator.Frame.Bottom + 1, 320, 140));
DescriptionWebView.DataDetectorTypes = UIDataDetectorType.All;
DescriptionWebView.UserInteractionEnabled = true;
DescriptionWebView.Delegate = new PlanDescriptionWebViewDelegate(this);
foreach(UIView subview in DescriptionWebView.Subviews)
{
if(subview is UIScrollView)
(subview as UIScrollView).ScrollEnabled = false;
}
我正在使用委托内部的逻辑调整基于内容大小的WebView,如下所示:
public override bool ShouldStartLoad(UIWebView webView, MonoTouch.Foundation.NSUrlRequest request, UIWebViewNavigationType navigationType)
{
NSUrl url = request.Url;
if(navigationType == UIWebViewNavigationType.Other)
{
if(url.Scheme.ToString().Equals("ready"))
{
float contentHeight = Convert.ToInt32(url.Host);
if(contentHeight < _infoView.DescriptionWebView.Frame.Height)
contentHeight = _infoView.DescriptionWebView.Frame.Height;
RectangleF scrollViewFrame = _infoView.ScrollView.Frame;
RectangleF descriptionViewFrame = _infoView.DescriptionWebView.Frame;
BeginInvokeOnMainThread(() =>
{
_infoView.DescriptionWebView.Frame = new RectangleF(descriptionViewFrame.X, descriptionViewFrame.Y, descriptionViewFrame.Width, contentHeight + 10);
//_infoView.ScrollView.ContentSize = new SizeF(scrollViewFrame.Size.Width, contentHeight + scrollViewFrame.Y + scrollViewFrame.Height - descriptionViewFrame.Height);
_infoView.ScrollView.ContentSize = new SizeF(scrollViewFrame.Size.Width, contentHeight + scrollViewFrame.Height + 20 - descriptionViewFrame.Height);
});
return false;
}
} else if(navigationType == UIWebViewNavigationType.LinkClicked)
{
UIApplication.SharedApplication.OpenUrl(url);
return false;
}
return true;
}
我完全不知所措。为什么视图中顶部的链接工作,而我必须滚动的底部的链接不会?
非常感谢任何帮助。