Re: Subview bounds resizing when frame resizes
Re: Subview bounds resizing when frame resizes
- Subject: Re: Subview bounds resizing when frame resizes
- From: Steve Weller <email@hidden>
- Date: Sun, 2 Mar 2008 20:00:30 -0800
On Mar 2, 2008, at 4:03 PM, Steve Weller wrote:
I have a custom view with a custom subview. I can't seem t make the
bounds of the subview stick. When the view changes the subview's
frame, I want the subview's bounds to stay exactly as I set them the
first time. The whole point of having this subview is to have a
separate coordinate system.
I create the subview like this:
// Add page into our view
pageView = [[BTPPPageView alloc] initWithFrame:[self pageFrame]];
[pageView
setBounds:NSMakeRect(0,0,pageBoundsSize.width,pageBoundsSize.height)];
[self addSubview:pageView];
and I reposition the subview's frame when the view's frame changes:
[pageView setFrame:[self pageFrame]];
The subview bounds are set correctly at the start, but if I make the
subview's frame larger, the bounds are scaled larger too. I thought
from this in the NSView docs that the subview's bounds would stay
fixed:
If your view does not use a custom bounds rectangle, this method
also sets your view bounds to match the size of the new frame. You
specify a custom bounds rectangle by calling setBounds:,
setBoundsOrigin:, setBoundsRotation:, or setBoundsSize:explicitly.
Once set, NSView creates an internal transform to convert from frame
coordinates to bounds coordinates.
I am using setBounds, so why is it not preventing the scaling? My
view has the Autoresizes subviews flag off. The view is created in
IB, the subview in code, as above.
Having discovered that all uses of setFrame that I could find that
handle scaling reset the bounds every time, I changed the code to:
[pageView setFrame:[self pageFrame]];
[pageView
setBounds:NSMakeRect(0,0,pageBoundsSize.width,pageBoundsSize.height)];
and this achieves what I wanted to do.
_______________________________________________
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