Resizing UIView: Content CALayer doesn't resize
Resizing UIView: Content CALayer doesn't resize
- Subject: Resizing UIView: Content CALayer doesn't resize
- From: Fritz Anderson <email@hidden>
- Date: Mon, 14 Jan 2013 13:27:34 -0600
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 (email@hidden)
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:
This email sent to email@hidden