• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Centering an Image in an NSScrollView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Centering an Image in an NSScrollView


  • Subject: Centering an Image in an NSScrollView
  • From: jean-michel daix <email@hidden>
  • Date: Mon, 01 Jul 2002 09:54:36 +0200

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.

- (BOOL)isFlipped
{
return YES;
}

- (void)drawRect:(NSRect)rect {
[self hideOrShowScrollers]; //Test if the image is bigger than the view
[self centerFrame];
[super drawRect:rect];
}

- (void)centerFrame
{
NSSize scrollViewSize = [[[self superview] superview] frame].size;
NSSize frameSize = [self frame].size ;
NSPoint frameOrigin;

frameOrigin.x = frameOrigin.y = 0.0;

if ( scrollViewSize.width >= frameSize.width )
frameOrigin.x=((long) (scrollViewSize.width-frameSize.width))/2;
if ( scrollViewSize.height >= frameSize.height )
frameOrigin.y=((long) (scrollViewSize.height-frameSize.height))/2;

[[self superview] setFrameOrigin:frameOrigin];
}


Well, it works. Except that sometimes the background is not refreshed (When
using the zoom buttton for exemple), so I think it's not the right method to
do that. May be someone can tell me a better way or how to refresh my
background. Thanks.


-----------------------------------
Jean-Michel DAIX / <email@hidden>
Sorry, I9m French !

visit <http://www.adforum.com>
_______________________________________________
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.

  • Follow-Ups:
    • Re: Centering an Image in an NSScrollView
      • From: Charles Jolley <email@hidden>
    • Re: Centering an Image in an NSScrollView
      • From: Jason Harris <email@hidden>
  • Prev by Date: NSString character manipulation...
  • Next by Date: Re: NSCopyBits and expose events
  • Previous by thread: Re: NSString character manipulation...
  • Next by thread: Re: Centering an Image in an NSScrollView
  • Index(es):
    • Date
    • Thread