NSScroller and Spotlight-like interface
NSScroller and Spotlight-like interface
- Subject: NSScroller and Spotlight-like interface
- From: Don Willems <email@hidden>
- Date: Tue, 7 Aug 2007 00:14:28 +0200
Hi,
I have a problem with an NSScroller and am wondering if someone can
help.
I'm trying to create an interface like the Spotlight window, with an
NSTableView on the left side of the window,
a view for navigating on the right side of the table, and the
scrollbar (part of the NSScrollView) on the right side of the
navigation view.
I got it to work by deselecting Display Vertical Scroller of the
NSTableView in Interface Builder. and then using [_scrollview
verticalScroller] to extract the scroller and then adding it to the
view containing the NSScrollView and the navigation view (see code
below).
When I start the application, everything is in the right place. But
unfortunately, the scroller is not displaying correctly. The size of
the scroller handle (the knobProportion) is 1.0. Even though the
document view in the scroll view is several times the size of the
scrollview. Furthermore, the scroller is displayed on top of the
resize handle of the window.
If I resize the window, the scroller is moved automatically so that
the resize handles become visible (but the up arrow button disappears
behind the window title bar.
If I resize the window again (not once but a few times), the scroller
resizes and the up arrow button becomes visible. The scroller is now
in the correct position and of the correct size. Unfortunately, the
knobProportion still has a value of 1.0.
But when I resize the window again for a few times, the
knobProportion does get the correct value (about 0.2 in my test app).
Does anybody have an idea what is going on here?
Many thanks,
Don
float frw = [self frame].size.width;
div2 = frw-vsw; // x position of the scroller
div1 = div2-nvw; // x position of the navigation view
NSRect svf = [self frame]; // the frame of the containing view
svf.size.width = div1;
[_scrollView setFrame:svf]; // set the scroll view size
NSRect nvf = [self frame];
nvf.origin.x = nvf.origin.x+div1;
nvf.size.width = nvw;
[_navView setFrame:nvf]; // set the navigation view size
NSRect sf = [self frame]; // the new frame of the scroller
sf.origin.x = sf.origin.x+div2;
sf.size.width = vsw;
_scroller = [[_scrollView verticalScroller] retain]; // get the
vertical scroller from the
// scrollview
[_scroller setFrame:sf];
// boundsDidChange: is called when the bounds of the content view
change
[[_scrollView contentView] setPostsBoundsChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(boundsDidChange:)
name:NSViewBoundsDidChangeNotification object:[_scrollView
contentView]];
// Adding subviews and setting resizing mask
[self addSubview:_scrollView];
[_navView setAutoresizingMask:NSViewMinXMargin|NSViewHeightSizable];
[self addSubview:_navView];
[_scroller setAutoresizingMask:NSViewMinXMargin|NSViewHeightSizable];
[self addSubview:_scroller];
// Calculate the desired knobproportion (1.0 fills the whole
scroller).
float kns = [_scrollView documentVisibleRect].size.height/
[[_scrollView documentView] frame].size.height;
[_scroller setFloatValue:[_scroller floatValue] knobProportion:kns];
[self setAutoresizesSubviews:YES];
[_scroller setNeedsDisplay:YES];
...
- (void) boundsDidChange:(NSNotification*)not
{
// Calculate the desired knobproportion (1.0 fills the whole scroller).
float kns = [_scrollView documentVisibleRect].size.height/
[[_scrollView documentView] frame].size.height;
[_scroller setFloatValue:[_scroller floatValue] knobProportion:kns];
[_scroller updateCell:[_scroller cell]];
}
_______________________________________________
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