Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

the scrolling map, resizing a custom view

0 views
Skip to first unread message

Tony Belding

unread,
May 25, 2005, 6:45:10 PM5/25/05
to
I sure could use some more explanation of how to scroll around with a
custom view and NSScrollView.

Here's what I've done so far. . . .

* I created a custom view with a drawRect method to render my graphic,
which is a sort of map.

* I put it into a NSScrollView and made the window resizeable.

It works, it displays -- but I've got a problem I'm trying to figure
out. Maps come in various sizes, and they get clipped when they are
bigger than my custom view. I need a way to change the size of my view
contents, meaning the rendering area (not visible area), to make room
for the whole map I'm displaying. (Or conversely, make it smaller to
fit a small map.)

The first thing I tried was the "setBounds" method. But that didn't do
it. . . Instead of changing the size of my view, it ended up *scaling*
my map to fit the view's current size. That's neat trick. . . but
that's not what I need to do here.

Any explanations, tips, or even pointing me toward the documentation
for this will be much appreciated.

--
Tony Belding, Hamilton Texas

matt neuburg

unread,
May 25, 2005, 7:02:48 PM5/25/05
to
Tony Belding <zob...@techie.com> wrote:

> I sure could use some more explanation of how to scroll around with a
> custom view and NSScrollView.
>
> Here's what I've done so far. . . .
>
> * I created a custom view with a drawRect method to render my graphic,
> which is a sort of map.
>
> * I put it into a NSScrollView and made the window resizeable.
>
> It works, it displays -- but I've got a problem I'm trying to figure
> out. Maps come in various sizes, and they get clipped when they are
> bigger than my custom view. I need a way to change the size of my view
> contents, meaning the rendering area (not visible area), to make room
> for the whole map I'm displaying. (Or conversely, make it smaller to
> fit a small map.)
>
> The first thing I tried was the "setBounds" method. But that didn't do
> it. . . Instead of changing the size of my view, it ended up *scaling*
> my map to fit the view's current size. That's neat trick. . . but
> that's not what I need to do here.

Set the frameSize of the custom view to match the contentSize of the
scroll view. m.

--
matt neuburg, phd = ma...@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/exec/obidos/ASIN/0596005571
Read TidBITS! It's free and smart. http://www.tidbits.com

Tony Belding

unread,
May 25, 2005, 9:08:22 PM5/25/05
to
On 2005-05-25 18:02:48 -0500, ma...@tidbits.com (matt neuburg) said:

> Set the frameSize of the custom view to match the contentSize of the
> scroll view. m.

Thank you! That worked.

Actually. . . What I did was set the frameSize equal to the calculated
size of my map. The scrollview appears to take care of itself, as far
as I can see.

Next thing I'll try is figuring out how to scroll to a part of the map
programmatically.

matt neuburg

unread,
May 25, 2005, 11:35:47 PM5/25/05
to
Tony Belding <zob...@techie.com> wrote:

Let me save you some trouble, because this part is *really* hard to
figure out from the online manual. You set the origin of the clip view -
this is the content view of your custom view. m.

matt neuburg

unread,
May 26, 2005, 8:54:20 AM5/26/05
to
matt neuburg <ma...@tidbits.com> wrote:

> Tony Belding <zob...@techie.com> wrote:
>
> > On 2005-05-25 18:02:48 -0500, ma...@tidbits.com (matt neuburg) said:
> >
> > > Set the frameSize of the custom view to match the contentSize of the
> > > scroll view. m.
> >
> > Thank you! That worked.
> >
> > Actually. . . What I did was set the frameSize equal to the calculated
> > size of my map. The scrollview appears to take care of itself, as far
> > as I can see.
> >
> > Next thing I'll try is figuring out how to scroll to a part of the map
> > programmatically.
>
> Let me save you some trouble, because this part is *really* hard to
> figure out from the online manual. You set the origin of the clip view -
> this is the content view of your custom view.

I mean it's the content view of the scroll view that contains your
custom view. See why this is hard to explain??? :) m.

Tony Belding

unread,
May 26, 2005, 9:30:37 AM5/26/05
to
On 2005-05-25 22:35:47 -0500, ma...@tidbits.com (matt neuburg) said:

> Let me save you some trouble, because this part is *really* hard to
> figure out from the online manual. You set the origin of the clip view -
> this is the content view of your custom view. m.

Thank you, that helped! Here's what I did:

NSClipView *clipper = [myScrollView contentView];
NSPoint origin;
origin.x = 100.0;
origin.y = 100.0;
[clipper scrollToPoint:origin];

So far, so good. . . It scrolls to the specified point, but it
doesn't update the scroll bars to match. I guess I'll need some
additional code to update those.

matt neuburg

unread,
May 26, 2005, 10:20:42 AM5/26/05
to
Tony Belding <zob...@techie.com> wrote:

Simply tell the scroll view to reflectScrolledClipView:. m.

Tony Belding

unread,
May 26, 2005, 11:05:11 AM5/26/05
to
On 2005-05-26 09:20:42 -0500, ma...@tidbits.com (matt neuburg) said:

>> So far, so good. . . It scrolls to the specified point, but it
>> doesn't update the scroll bars to match. I guess I'll need some
>> additional code to update those.
>
> Simply tell the scroll view to reflectScrolledClipView:. m.

Oh, cool! I thought I'd have to get to the actual scrollbar objects,
do my own calculations, and then explicitly set them to the new
positions.

I should have known better. :) Everything turns out to be so easy
with Cocoa, I love it. I just need to get more familiar with it.

Thanks again for your help!

0 new messages