iOS:调整 UIWebView 的高度 - 奇怪的行为
<p><p>我有一个问题。在 <code>Xcode</code> 我有一个 <code>ViewController</code> 嵌入 View > <code>ScrollView</code> 并且 Scrollview 内部是一个 UIWebView。</p>
<p>应用程序读取一些 XML 数据并将格式化的文本粘贴到 <code>UIWebView</code> 中。 <code>UIWebView-Element</code>之后是另一个Element,所以我要动态调整<code>UIWebView</code>的高度。</p>
<p>加载 View 后一切正常,但是当我点击屏幕时, View 将 <code>scrollview</code> 重新调整为 Storyboard高度。</p>
<p>为什么?</p>
<pre><code>- (void)webViewDidFinishLoad:(UIWebView *)aWebView
{
aWebView.scrollView.scrollEnabled = NO; // Property available in iOS 5.0 and later
CGRect frame = aWebView.frame;
frame.size.width = 280; // Your desired width here.
frame.size.height = 1; // Set the height to a small one.
aWebView.frame = frame; // Set webView's Frame, forcing the Layout of its embedded scrollView with current Frame's constraints (Width set above).
frame.size.height = aWebView.scrollView.contentSize.height;// Get the corresponding height from the webView's embedded scrollView.
aWebView.frame = frame; // Set the scrollView contentHeight back to the frame itself.
NSLog(@"size: %f, %f", aWebView.frame.size.width, aWebView.frame.size.height);
// Position URL Label
CGRect frame_label = fachmesseDetailWebsite.frame;
NSLog(@"x: %f", frame_label.origin.x);
NSLog(@"y: %f", frame_label.origin.y);
frame_label.origin.y=aWebView.frame.size.height+115;//pass the cordinate which you want
frame_label.origin.x= 20;//pass the cordinate which you want
fachmesseDetailWebsite.frame= frame_label;
NSLog(@"x: %f", frame_label.origin.x);
NSLog(@"y: %f", frame_label.origin.y);
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>每当您更改框架时,您必须重新加载 webview,然后只有 webview 框架会更改您放置的任何内容,否则它不会影响 webview。</p>
<pre><code>;
</code></pre>
<p>编辑:
这个工作</p>
<pre><code>UIWebView *web=[initWithFrame:CGRectMake(0, 0, 100, 100)];
NSString* html = ;
;
;
</code></pre></p>
<p style="font-size: 20px;">关于iOS:调整 UIWebView 的高度 - 奇怪的行为,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/16185258/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/16185258/
</a>
</p>
页:
[1]