Re: keeping view's bounds fixed
Re: keeping view's bounds fixed
- Subject: Re: keeping view's bounds fixed
- From: Quincey Morris <email@hidden>
- Date: Mon, 28 Jan 2008 21:30:03 -0800
On Jan 28, 2008, at 20:38, Nathan Vander Wilt wrote:
Since I *have* explicitly set the bounds rectangle,
why is it still being automatically updated to match
the frame's height/width? Where can I reset the
bounds, so that they always are set to
NSMakeRect(-180, -90, 360, 180) when my view's
drawRect is called? The -viewDidEndLiveResize method
will not work, because that message isn't passed when
the window's zoom button is activated.
I don't have the "why?", but I did have a similar situation and after
lots of hair-tearing-out the only reliable way I found was to monitor
frame-change notifications. In my case, the view was inside a scroll
view, so I needed to work off the scroll view's clip view, but if you
don't have that complication, I think it would be fine to watch your
own frame-change notification:
// version A
[self setPostsFrameChangedNotifications: YES];
[[NSNotificationCenter defaultCenter] addObserver: self selector:
@selector (frameDidChangeNotification:) name:
NSViewFrameDidChangeNotification object: self];
or possibly the superview's:
// version B
[[self superview] setPostsFrameChangedNotifications: YES];
[[NSNotificationCenter defaultCenter] addObserver: self selector:
@selector (frameDidChangeNotification:) name:
NSViewFrameDidChangeNotification object: [self superview]];
which is what I actually did, since the clip view was my view's
superview. Then all you need is:
- (void) frameDidChangeNotification: (NSNotification*) notification {
[self setBounds: NSMakeRect (-180, -90, 360, 180)];
}
The only thing to be careful of is not to cause an endless loop of
notifications. (Setting your view's frame inside the notification
method is fine with version B of the setup, but not so good with
version A.)
_______________________________________________
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