One more thing. Here's the skeleton of the HTML I'm feeding to the web view. It may be a coincidence, but the height the view eventually attains (which is not the .preferredHeight it is set to) is pretty good for the first two paragraphs of the #content <div>.
(id="content" looks collision-prone, but changing the ID to "paragraphs" doesn't help.) — F <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <title></title> <style type="text/css"></style> </head> <body> <div id="content"> <p><strong></strong></p> <p><strong></strong></p> <p><strong></strong></p> </div> </body> </html> On 14 Jan 2013, at 2:17 PM, Fritz Anderson <fri...@manoverboard.org> wrote: > I'd forgotten that when I created the web view, I set the autoresizing flags > so the height and width are flexible. Here is the new windowDidFinishLoad: > > - (void) webViewDidFinishLoad: (UIWebView *) webView > { > CGRect myFrame = self.frame; > myFrame.size.height = self.preferredHeight; > self.frame = myFrame; > } > > With this arrangement, the overlay view and its gradient remain shorter than > the 149 points returned by .preferred height. The web view is now the same > too-short size. > > — F > > > On 14 Jan 2013, at 1:27 PM, Fritz Anderson <fri...@manoverboard.org> wrote: > >> For a kiosk-style iPad app, I have a UIViewController (outer controller) >> that responds to a button my allocating an overlay view and making it a >> subview of the outer controller's view. The outer controller sets the >> overlay's height to 100 as a placeholder. >> >> The overlay view contains a UIWebView. After the overlay is initialized, it >> loads an HTML string into the web view. Upon webViewDidFinishLoad:, the >> overlay asks the web view for the height of its contents, and adjusts the >> heights of the web view, and a gradient layer, and itself to the content >> height. See the code at the end of this message. >> >> The preferred height is 149. >> >> I've subclassed CALayer and CAGradientLayer so I can break on setBounds: and >> setFrame:. What I see is that the overlay, its root layer, the web view, and >> the gradient layer get initial heights of 100, but once >> webViewDidFinishLoad: is called, the heights are set to 149. Nothing else. >> -setTransform: is never called on the layers or the view. >> >> I've put colored borders on the root layer, the gradient layer, and the web >> view's root layer, so I can measure them on the screen. What I'm seeing: The >> web view is sized as expected (149). The overlay's root and the gradient >> display at 113 points height. The layers' bounds and frames were not changed >> from a height of 149. >> >> Note, by the way, that at the end of webViewDidFinishLoad:, the web view's >> height is reported as 198. Another headache, though the drawn dimension is >> correct. >> >> This is wrong. Could someone please tell me what my next step should be? >> >> — F >> >> >> - (CGFloat) preferredHeight >> { >> NSString * answer = [self.webView stringByEvaluatingJavaScriptFromString: >> >> @"document.getElementById(\"content\").offsetHeight;"]; >> return MAX(answer.floatValue, 100.0); >> // Returns 149 >> } >> >> - (void) webViewDidFinishLoad: (UIWebView *) webView // == self.webView >> { >> CGRect webViewFrame = self.webView.frame; >> webViewFrame.size.height = self.preferredHeight; >> self.webView.frame = webViewFrame; >> >> CGRect myFrame = self.frame; >> myFrame.size = webViewFrame.size; >> self.frame = myFrame; >> // setBounds on the root layer: origin=(x=0, y=0) size=(width=984, >> height=149) >> >> self.gradientLayer.frame = self.layer.bounds; >> // setBounds on gradient layer = origin=(x=0, y=0) size=(width=984, >> height=149) >> >> // self.layer.frame = origin=(x=20, y=200) size=(width=984, height=149) >> // self.gradientLayer.frame = origin=(x=0, y=0) size=(width=984, >> height=149) >> // self.webView.frame = (0 0; 984 198) >> // self.frame = origin=(x=20, y=200) size=(width=984, height=149) >> } >> >> // 113, 149 >> >> >> >> -- >> Fritz Anderson >> Xcode 4 Unleashed: 4.5 supplement for free! >> http://www.informit.com/store/xcode-4-unleashed-9780672333279 >> >> >> _______________________________________________ >> >> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >> >> Please do not post admin requests or moderator comments to the list. >> Contact the moderators at cocoa-dev-admins(at)lists.apple.com >> >> Help/Unsubscribe/Update your Subscription: >> https://lists.apple.com/mailman/options/cocoa-dev/fritza%40manoverboard.org >> >> This email sent to fri...@manoverboard.org > > -- > Fritz Anderson > Xcode 4 Unleashed: 4.5 supplement for free! > http://www.informit.com/store/xcode-4-unleashed-9780672333279 > > -- Fritz Anderson Xcode 4 Unleashed: 4.5 supplement for free! http://www.informit.com/store/xcode-4-unleashed-9780672333279 _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com