Confused about UIView frame property

Posted by slowfungus on Stack Overflow See other posts from Stack Overflow or by slowfungus
Published on 2010-03-30T22:42:43Z Indexed on 2010/03/30 23:33 UTC
Read the original article Hit count: 265

Filed under:
|
|
|

I'm building a prototype iPad app that draws diagrams. I have the following view hierarchy:

UIView UIScrollView DiagramView : UIView TabBar NavigationBar

And a UIViewController subclass holding all that together.

Before drawing the diagram the first time I calculate the dimensions of the diagram, and set the DiagramView frame to that size, and the content size of the scrollview as well.

-(void)recalculateBounds
{
 [renderer diagram:diagram shouldDraw:NO];
 SQXRect diagramRect = SQXMakeRect(0.0,0.0,[diagram bounds].size.width,[diagram bounds].size.height);
 self.frame = diagramRect;
 [(UIScrollView*)[self superview] setContentSize:diagramRect.size];
}

I should disclose that the frame is being set to about 1500 x 3500 which i know is ridiculous. I just want to focus on some other parts of the app before I get into optimizing the render code.

This works beautifully, except that the rect being passed to drawRect is not the size that I set, and my drawing is getting clipped at the bottom. Its close the size i set, but bigger in width, and shorter in height.

Also of note, is the fact that if I force the frame to be much bigger than what I know the diagram needs, then the drawRect:rect is big enough, and no clipping occurs. Of course this has me wondering if the frame size needs to take into account some other screen real estate like the toolbars but my reading of the docs tells me the frame is in superview coordinates, which would be the scrollview so I reckon I need to worry about such things.

Any idea what is causing this discrepancy?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ipad