Re: Problem centering inside a scrollview
Re: Problem centering inside a scrollview
- Subject: Re: Problem centering inside a scrollview
- From: Matt Neuburg <email@hidden>
- Date: Wed, 10 Aug 2005 12:16:52 -0700
On Sun, 24 Jul 2005 15:00:44 -0400, Matt Ball <email@hidden>
said:
>I've gotten it so that my scrollView's contentView gets centered
>inside of the scrollview. However, I have a custom cursor set for my
>scrollView's documentView. With my centering code in place, the cursor
>stays the normal arrow until I get to the centered view (as expected).
>However, when I move the mouse below or to the right of my view, the
>cursor stays changed instead of reverting to the arrow. Here's the
>code that is called whenever the scrollview is resized:
>
>- (void)centerCanvas {
> NSRect newBounds = [[self contentView] bounds];
> NSRect newFrame = [[self contentView] frame];
> if([self frame].size.width > newFrame.size.width || [self
>frame].size.height > newFrame.size.height) {
> if((newBounds.size.width - [[self documentView] frame].size.width)/2 > 0)
> newFrame.origin.x = (newBounds.size.width - [[self documentView]
>frame].size.width)/2;
> if((newBounds.size.height - [[self documentView] frame].size.height)/2 > 0)
> newFrame.origin.y = (newBounds.size.height - [[self documentView]
>frame].size.height)/2;
>
> [[self contentView] setFrame:newFrame];
> [self setNeedsDisplay:YES];
> }
>}
>
>I added in the following lines, and the cursor problem was fixed:
>
> newFrame.size.width = [[self documentView] frame].size.width;
> newFrame.size.height = [[self documentView] frame].size.height;
>
>However, with that code in place, the scroll bars do not appear when
>they should. So, I know the problem is that the clipview is only
>having its origin moved, and its size isn't changing. Does anyone know
>how I can fix this?
You probably should be using a cursor rect instead the (much grosser)
document view cursor. It sounds also like there are perhaps some problems
here in coordinate systems and in getting your ducks in a row in your
drawing code. I have code demonstrating how to center an image in a scroll
view, dealing with resizing of the scroll view, showing a custom cursor when
the mouse is over the image, and allowing the image to be scrolled by
dragging. Let me know offline if you need this and I'll send it to you. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
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