Re: [NEWBIE]: Scrolling windows
Re: [NEWBIE]: Scrolling windows
- Subject: Re: [NEWBIE]: Scrolling windows
- From: "Louis C. Sacha" <email@hidden>
- Date: Fri, 15 Oct 2004 05:58:29 -0700
Hello...
There are a couple of things that are contributing to the problem.
You might want to take a look at the info on scroll views in the
conceptual documentation to get a better idea of how a scroll view
works.
<
http://developer.apple.com/documentation/Cocoa/Conceptual/DrawViews/index.html#//apple_ref/doc/uid/10000079i>
First, the NSClipView is part of the NSScrollView, and is taken care
of automatically so you don't need to make your own. Also, the view
that is scrolled in a NSScrollView is the "document view" and instead
of adding it as a subview, you use the NSScrollView setDocumentView:
instance method to set it.
Also, the frame of a window includes the title bar and any other
extra space that is part of the window, so what you probably want to
set is the content size of the window instead of the frame rect.
NSWindow provides both class and instance methods for calculating
back and forth from the content size to the window frame rect, or you
can just use the setContentSize: instance method.
If you want the window to start with a size so that it is displaying
your entire projectPrintView, you also need to take the extra space
required for the scroller in the NSScrollView into account.
NSScrollView provides the class method
frameSizeForContentSize:hasHorizontalScroller:hasVerticalScroller:borderType:
where you plug in the information and it will calculate the correct
frame size.
So, based on the code you had included, it could look something like this:
/* ... typed in mail, etc... */
startingSize.size.height = 600;
startingSize.size.width = 650;
[projectPrintView setFrame:startingSize];
NSScrollView *scrollView = [[NSScrollView alloc]
initWithFrame:[[printWindow contentView] frame]];
[scrollView setHasVerticalScroller:YES];
[scrollView setDocumentView:projectPrintView];
[printWindow setContentView:scrollView];
[printWindow setBackgroundColor:[NSColor
colorWithCalibratedWhite:100 alpha:100]];
NSSize wholeSize = [NSScrollView
frameSizeForContentSize:startingSize hasHorizontalScroller:FALSE
hasVerticalScroller:TRUE borderType:[scrollView borderType]];
[printWindow setContentSize:wholeSize];
[scrollView release];
If you don't want the window to be resized larger than is required to
display the whole view, then you will want to set up limits on the
max size of the window.
Also, if I remember correctly, using a NSScrollView instance as the
content view of a window may cause problems under 10.2 (overlap of
the scroller arrow and window resize widget) unless both scrollers
are always displayed. If you are supporting 10.2, you'll probably
want to specifically check this and make sure it's working okay.
Hope that helps,
Louis
Pretty simple. Creating a scrollview, and clip, setting it to a
default size. Adding the scroll to the clip, and adding my custom
view to the scroll. The making the clip the contentView of my window.
I'm obviously missing a step because when I try and resize my
window, the scroll stays locked to it's original size. If the
material in my view exceeds the original size, my scroll doesn't
kick in with it's scrollers.
Anyway, I know I have missed something, but I can't for the life of
me figure out what I should be doing. Delegate methods for the
scrollView? For the clip?Maybe someone can send out a link to
another article or something that might explain things. I dunno.
~j~
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden