Note that there are some explanatory texts on larger screens.

plurals
  1. POUIWebView sizeThatFits incorrect in Landscape mode, multiple paragpraphs
    primarykey
    data
    text
    <p>I Have a UIView in a UINavigationController view stack. Inside the UIView I have a UIWebView, which gets populated with HTML formatted text (originally download from an xml file and stored in coredata).</p> <p>I want the UIWebView to expand vertically to fit the content so I call this code:</p> <pre><code>int screenWidth = self.view.frame.size.width - 40; CGRect frame = descText.frame; frame.size.height = 1; frame.size.width = screenWidth; descText.frame = frame; CGSize fittingSize = [descText CGSizeZero]; frame.size = fittingSize; </code></pre> <p>This works fine when the View is loaded in Portrait mode but when loaded in landscape. it expands too far, nearly double. The reason for this is that sizeThatFits returns a height that is far too big:</p> <pre><code>2011-05-05 14:16:20.268 DesignFedApp[2792:207] CURRENT SIZE: {293, 592} FITTING SIZE: {293, 592} 2011-05-05 14:16:26.282 DesignFedApp[2792:207] new orientation = 4 2011-05-05 14:16:26.283 DesignFedApp[2792:207] new orientation = 4 2011-05-05 14:16:26.283 DesignFedApp[2792:207] ROOT!! willRoatetToInterfaceOrientation!!!!!!!!!!! 2011-05-05 14:16:27.452 DesignFedApp[2792:207] CELL CLICKED: 1 2011-05-05 14:16:27.452 DesignFedApp[2792:207] LocNavController locSelected 2011-05-05 14:16:27.453 DesignFedApp[2792:207] Loc: The Hood 2011-05-05 14:16:27.459 DesignFedApp[2792:207] should rotate to LANDSCAPE 2011-05-05 14:16:27.481 DesignFedApp[2792:207] POSITION ELEMENTS view.width {{0, 0}, {480, 268}} 2011-05-05 14:16:27.483 DesignFedApp[2792:207] CURRENT SIZE: {440, 761} FITTING SIZE: {440, 761} </code></pre> <p>The really weird thing is that this does not happen when the HTML being loaded only consists of 1 p tag!!!! Multiple <p> tags and we have the issue described above. But only in Landscape. </p> <p>So to re-cap. UIWebView sizeThatFits return incorrect height, but only in landscape mode and only when html has more than one p tag.</p> <p>If anyone can shed any light on this it could save me weeks of time, I've been reading though so many forums and all the Apple docs but haven't found anything that can help me with this specific case.</p> <p>Thanks in advance, Ian.</p> <p><strong>EDIT:</strong> OK I've noticed that the problem only occurs if the loaded HTML String has more than 1 tag set in it:</p> <pre><code>NSString *html=@"&lt;p&gt;This is a parapgrah this will work fine......&lt;/p&gt;"; NSString *html2=@"&lt;p&gt;This is a paragraph with other &lt;i&gt;tags&lt;/i&gt;, this wont work properly&lt;/p&gt;"; </code></pre> <p>Whole Method. Called from webViewDidFinishLoad:webView</p> <pre><code>-(void)positionElements:(BOOL)inLandScape{ NSLog(@"position elements"); //stretch frame to fit content int screenWidth = self.view.frame.size.width - 40; CGRect frame = descText.frame; frame.size.height = 1; frame.size.width = screenWidth; descText.frame = frame; CGSize fittingSize = [descText sizeThatFits:CGSizeZero]; NSLog(@"fittingSize: %@",NSStringFromCGSize(fittingSize)); frame.size = fittingSize; descText.frame = frame; //position buttons underneath CGRect mapBtnFrame = showOnMapBtn.frame; mapBtnFrame.origin.y = frame.origin.y + frame.size.height + 20; showOnMapBtn.frame = mapBtnFrame; CGRect locBtnFrame = locationInfoBtn.frame; locBtnFrame.origin.y = mapBtnFrame.origin.y + mapBtnFrame.size.height + 20; locationInfoBtn.frame = locBtnFrame; CGRect scrollFrame = self.view.frame; scrollFrame.size.height -= 49; container.frame = scrollFrame; CGRect contentRect = CGRectZero; for (UIView *containerSubView in container.subviews) contentRect = CGRectUnion(contentRect, containerSubView.frame); container.contentSize = contentRect.size; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload