Re: Centering an Image in an NSScrollView
Re: Centering an Image in an NSScrollView
- Subject: Re: Centering an Image in an NSScrollView
- From: David Masters <email@hidden>
- Date: Mon, 1 Jul 2002 12:19:37 +0100
Hi,
On Monday, July 1, 2002, at 09:50 AM, Jason Harris wrote:
Subclass NSScrollView and write a setFrameSize: method that calls
super's
implementation and then re-centers your image.
Jason Harris
jean-michel daix Tried to Tell Me:
Hi,
As I think many people, I'm trying to centering an Image in a document
based
application using an NSScrollView. I mean when I enlarge my window, I
want
my image to stay centered in the window. In my custom ImageView I use
this
code.
Funny that - I'm one of the other people doing exactly the same thing! I
hadn't thought about Jason's suggestion of subclassing NSScrollView
which - now that I think of it - might have been a simpler solution.
My solution was to have a class which sits within the scrollview and
acts as a background. This class then has an image view as its subview,
and looks after the custom resizing behavior in
-resizeWithOldSuperviewSize. Should be relatively simple to fold the
resizing behavior into a subclass of NSScrollView if you wanted to.
This currently works quite nicely - resizing the window keeps the image
in the center, unless the window is smaller than the image in which case
the image view is pinned to the top-left corner, and the scroll bars
become active.
If anyone wants a copy of a sample project which shows this working,
email me off-list.
David
David Masters, Software Imagineer
email@hidden
Web:
http://www.pyrusmalus.com Tel: +44 141 427 9649 Fax: +44 141
427 1740
P y r u s M a l u s | d e s i g n | d e v e l o p | d e l i
v e r | c o n s u l t | t r a i n | s u p p o r t |
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.