Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sizing view in NSScrollView



Hi,

I've gotten pretty far (for me) without really asking a question,
but I'm stumped now. A quick view of the application can be
found at http://homepage.mac.com/~chamlin/boxview/ if
that helps.

I'm viewing a page, and have put in an NSView, then done
the Make Subviews Of | ScrollView. In IB the scrollview has
max x,y of (567,442). The view itself has max x,y of (700,900)
(a little bigger than Letter size paper).

It seems that the frame and bounds of the view have the
same size as the view max (700,900). This seems to work OK
for me as is.

Then I added zooming. This is done by having a button
connected to the action

-(IBAction)magUp:(id)sender
{
NSLog (@"magUp, mag was %f.\n", mag);
mag *= 1.2;
if (mag > 10.0) mag = 10.0;
NSLog (@"magUp, mag now %f.\n", mag);
[theView setNeedsDisplay:YES];
}

and in the drawing routine I have

// scale up
transform_matrix = [NSAffineTransform transform];
[transform_matrix scaleXBy: mag yBy: mag];
[transform_matrix concat];

// gray background for contrast
[[NSColor lightGrayColor] set];
[NSBezierPath fillRect:myBounds];
[[NSColor yellowColor] set];

// hard-coded Letter-size page boundry
[NSBezierPath strokeRect: NSMakeRect (0,0,612,792)];

// this draws the page
[[pages objectAtIndex:pageViewed] drawInView:view];

The problem is that when I zoom in, the bounds/gray-background
stay the same size and the content is clipped to that. So with
high zoom I can only see a little of the content, even with a big
window. I tried resetting the bounds, but this just seems to have
the documented effect of scaling the content to fit, negating the
zoom.

I guess it is hard to say what I want, though it is probably pretty
normal and easy somehow. I'd like the canvas I'm drawing on to
be sized according to what size paper I'm viewing, and also
according to the current magnification. I'd like all the canvas that
fits to be drawn in the window, and the rest to be visible via
scrolling.

What am I doing wrong or missing?



Thanks for any pointers,

Chris Hamlin




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.