NSDrawer leading offset
NSDrawer leading offset
- Subject: NSDrawer leading offset
- From: Joe Wildish <email@hidden>
- Date: Sat, 7 Jul 2007 14:16:03 +0100
All,
I am having some difficulty in getting the offset of an NSDrawer
correct. Hopefully people on this list may be able to point me in the
right direction.
I want to make an NSDrawer maintain it's size relative to a custom
view in the window that it is attached to. The drawer is attached to
either the left or right of the window. I have been doing this by
setting the leading and trailing offsets of the drawer, and that
works fine.
However, the parent window has a toolbar; obviously this means that
the frame of the window can be various different heights, depending
on the state of the toolbar. As the leading offset of the drawer is
relative to the frame of the window, this means the offset needs to
be calculated by taking into account the toolbar state (I did play
with calling setLeadingOffset whenever the toolbar state was changed,
but this means the drawer does not animate in sync with the
displaying/hiding of the toolbar).
I have setup a class to pose as the drawer, and have overridden the
leadingOffset method (board is the custom view that I want the drawer
to be relative to):
- (float)leadingOffset {
float offset = [super leadingOffset];
id controller = [[self parentWindow] windowController];
if([controller isKindOfClass:[GameController class]] &&
[controller respondsToSelector:@selector(board)])
{
NSRect viewRect = [[controller board] frame];
float newOffset = [[self parentWindow] frame].size.height - [self
trailingOffset] - viewRect.size.height;
NSLog(@"Overriding offset (%f) with new offset (%f)", offset,
newOffset);
offset = newOffset;
}
return offset;
}
However, despite the log information indicating that the new offset
is calculated correctly, it seems to ignore this information despite
being returned! Thinking that I may need to call setLeadingOffset
instead, I changed the method to call the following, rather than
"offset = newOffset":
if(offset != newOffset) {
[super setLeadingOffset:newOffset];
offset = [super leadingOffset];
}
However, this seems to cause the app to go into an infinite loop :(
Can anyone see what I'm doing wrong, or suggest another approach to
try and get this to work?
Many thanks,
-Joe
_______________________________________________
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