我想在 UIScrollView 中添加一个 UIWebView(和一些其他元素)。
首先,我的 UIWebView 没有固定文本,可以更改。
所以,正如我在示例和教程中看到的那样,我可以这样做:
public class testArticleViewController : UIViewController
{
private UIScrollView _scrollView;
//Post elements
UIWebView _artcileTextWeb;
public testArticleViewController()
{
Title = "test";
View.BackgroundColor = UIColor.White;
}
public override void ViewDidLoad()
{
string text = @"L'un des deux meilleurs du monde, Lionel Messi, va-t-il manquer la Coupe du monde ? L'Argentine se retrouve dans une situation extrêmement délicate dans la course à la qualification au Mondial 2018 en faisant match nul (0-0) jeudi face au Pérou.<br />
<div>
<div>
<div>
<article>
<div>
<div>
<p ><br />Le risque de voir une Coupe du Monde en Russie sans Lionel Messi est bien réel : sixième et en dehors de la zone de qualification à une journée de la fin, l'Albiceleste doit impérativement s'imposer mardi face à l'Équateur, déjà éliminé.<br /><br />Cinq équipes se tiennent en deux points, entre le Chili (3e, 26 points) et le Paraguay (7e, 24 points) qui garde un mince espoir de qualification grâce à son succès de jeudi (2-1) face à la Colombie (4e, 26 points).<br /><br />L'Argentine ne pointe qu'en sixième position, avec le même nombre de points que les Péruviens (5e, 25), qui occupent pour le moment une place de barragiste et rêvent à une première participation au Mondial depuis 1982.</p>
<h3>Sampaoli est «très confiant»</h3>
<p>Même s'il admet que la position de l'Argentine <em>«n'est pas très confortable»</em>, le sélectionneur Jorge Sampaoli se veut <em>«très confiant dans le fait que nous allons être au Mondial»</em>. Pour le match crucial de jeudi face au Pérou, la Fédération argentine avait misé sur l'ambiance bouillante du mythique stade de la Bombonera.<br /><br />Poussés par quelque 50 000 supporters, les locaux ont eu beaucoup de mal à trouver des espaces face à des Péruviens bien regroupés derrière. Messi a cru ouvrir le score dès la 13e minute, sur une belle combinaison sur corner, mais un défenseur s'est jeté in extremis pour dévier un ballon qui semblait prendre la direction des filets. La Bombonera a soupiré une nouvelle fois dix minutes plus tard, quand Di Maria - remplacé à la pause - a manqué une belle occasion en tirant au-dessus.<br /><br />Les nerfs à vif, les supporters ont retenu leur souffle à la 33e, en voyant Farfan manquer le cadre de peu sur un centre à ras de terre Trauco. Messi bien touché le poteau au retour des vestiaires, mais l'Albiceleste a livré une nouvelle fois une copie bien pâle. <em>«On ne peut pas en demander plus à Leo Messi. Il a eu des opportunités, les a créées, a eu des balles de but. On a eu un Messi très intense, celui dont l'Argentine a besoin»</em>, a considéré Sampaoli.<br /><br />La dernière fois que l'Albiceleste a raté un Mondial (celui de 1970, au Mexique), elle avait été condamnée par un match nul (2-2) face au Pérou, dans ce même stade de la Bombonera. Cette fois, il reste encore un match, un seul, pour tout changer.</p>
</div>
</div>
</article>
</div>
</div>
</div>";
var padding = 10;
View.BackgroundColor = UIColor.White;
_scrollView = new UIScrollView()
{ ShowsHorizontalScrollIndicator = false, AutoresizingMask = UIViewAutoresizing.FlexibleHeight };
//Text article
_artcileTextWeb = new UIWebView();
_artcileTextWeb.LoadHtmlString(text, null);
_artcileTextWeb.ScrollView.ScrollEnabled = false;
var view1 = new UIView { BackgroundColor = UIColor.Blue };
var view3 = new UIView { BackgroundColor = UIColor.Green };
Add(_scrollView);
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
View.AddConstraints(
_scrollView.AtLeftOf(View),
_scrollView.AtTopOf(View),
_scrollView.WithSameWidth(View),
_scrollView.WithSameHeight(View));
_scrollView.Add(view1);
_scrollView.Add(_artcileTextWeb);
_scrollView.Add(view3);
_scrollView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
var basicwidth = (UIScreen.MainScreen.Bounds.Width - 3 * padding) / 2;
var basicheight = basicwidth / 2;
_scrollView.AddConstraints(
view1.AtTopOf(_scrollView, UIApplication.SharedApplication.StatusBarFrame.Height),
view1.AtLeftOf(_scrollView, padding),
view1.Width().EqualTo(basicwidth),
view1.Height().EqualTo(basicheight),
view3.WithSameTop(view1),
view3.Left().EqualTo().RightOf(view1).Plus(padding),
view3.WithSameHeight(view1),
view3.WithSameWidth(view1),
_artcileTextWeb.Below(view1, padding),
_artcileTextWeb.WithSameLeft(view1),
_artcileTextWeb.WithSameRight(view3),
_artcileTextWeb.WithSameHeight(_scrollView)
);
}
}
如果你运行它,你会看到 UIScrollView 具有相同的屏幕高度并且它不是动态的!
所以,也许 UIWebView 的高度似乎不正确(没有更正的框架大小)!如果是这样,我如何预测 UIWebView 的高度?
即使我使用 CGRect 创建将 UIWebView 的框架添加到我的 UIScrollView,我也需要一个高度!
亲爱的开发者,您有什么想法吗?
最佳答案
回复:Autolayouts in UIScrollView using Cirrious.FluentLayouts.Touch
设置UIWebView的contentSize,然后让它AtBottomOf Scrollview。
_artcileTextWeb.Below(view1, padding),
_artcileTextWeb.WithSameLeft(view1),
_artcileTextWeb.WithSameRight(view3),
_artcileTextWeb.Height().EqualTo(_artcileTextWeb.ScrollView.ContentSize.Height),
_artcileTextWeb.AtBottomOf(_scrollView)
但是它不起作用,ScrollView.ContentSize.Height 返回了不正确的结果。
_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(
//xxxx
_artcileTextWeb.Below(view1, padding),
_artcileTextWeb.WithSameLeft(view1),
_artcileTextWeb.WithSameRight(view3),
_artcileTextWeb.Height().EqualTo(height),
_artcileTextWeb.AtBottomOf(_scrollView)
);
结果总是返回667(屏幕高度),所以我将计算移至方法LoadingFinished,设置webview加载完成后的内容高度。
新建一个 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)));
}
}
在 View Controller 中
_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)
终于成功了。
关于c# - 在 UIScrollView XAMARIN.IOS C# 中添加 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47046146/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha
当谈到运行时自省(introspection)和动态代码生成时,我认为ruby没有任何竞争对手,可能除了一些lisp方言。前几天,我正在做一些代码练习来探索ruby的动态功能,我开始想知道如何向现有对象添加方法。以下是我能想到的3种方法:obj=Object.new#addamethoddirectlydefobj.new_method...end#addamethodindirectlywiththesingletonclassclass这只是冰山一角,因为我还没有探索instance_eval、module_eval和define_method的各种组合。是否有在线/离线资
我注意到类定义,如果我打开classMyClass,并在不覆盖的情况下添加一些东西我仍然得到了之前定义的原始方法。添加的新语句扩充了现有语句。但是对于方法定义,我仍然想要与类定义相同的行为,但是当我打开defmy_method时似乎,def中的现有语句和end被覆盖了,我需要重写一遍。那么有什么方法可以使方法定义的行为与定义相同,类似于super,但不一定是子类? 最佳答案 我想您正在寻找alias_method:classAalias_method:old_func,:funcdeffuncold_func#similartoca
我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
C#实现简易绘图工具一.引言实验目的:通过制作窗体应用程序(C#画图软件),熟悉基本的窗体设计过程以及控件设计,事件处理等,熟悉使用C#的winform窗体进行绘图的基本步骤,对于面向对象编程有更加深刻的体会.Tutorial任务设计一个具有基本功能的画图软件**·包括简单的新建文件,保存,重新绘图等功能**·实现一些基本图形的绘制,包括铅笔和基本形状等,学习橡皮工具的创建**·设计一个合理舒适的UI界面**注明:你可能需要先了解一些关于winform窗体应用程序绘图的基本知识,以及关于GDI+类和结构的知识二.实验环境Windows系统下的visualstudio2017C#窗体应用程序三.