FROM : Quincey Morris
DATE : Tue Jan 29 06:30:03 2008
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.)
DATE : Tue Jan 29 06:30:03 2008
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.)
| Related mails | Author | Date |
|---|---|---|
| Nathan Vander Wilt | Jan 29, 05:38 | |
| Quincey Morris | Jan 29, 06:30 | |
| Nathan Vander Wilt | Jan 29, 07:42 | |
| Ken Thomases | Jan 30, 05:51 |






Cocoa mail archive

