• 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 NSImageView in NSScrollView (again)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Centering an NSImageView in NSScrollView (again)


  • Subject: Centering an NSImageView in NSScrollView (again)
  • From: Jan Van Tol <email@hidden>
  • Date: Fri, 11 Oct 2002 22:47:52 -0500

I'm using the following code in an attempt to center my NSImageView in an NSScrollView:

In my setImage: method:

[imageView setImage:image];

[scrollView setDocumentView:comicView];
[imageView setNeedsDisplay:YES]; // Is this necessary?
[imageView setFrameSize:[image size]];
[imageView setImageAlignment:(NSImageAlignment)NSImageAlignCenter]; // Probably not necessary

Then:
- (void)windowDidResize:(NSNotification *)aNotification {
NSLog(@"windowDidResize"); // yes, this does run.

NSSize scrollViewSize = [scrollView frame].size;
NSSize frameSize = [imageView 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;
}

[imageView setFrameOrigin:frameOrigin];
}


The problem being, simply, the imageView doesn't center. It stays stubbornly anchored to the lower-left corner (yes, even after resizing the window.
Can anyone tell me what's wrong here?

Thanks in advance,

-Jan Van Tol
_______________________________________________
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.

  • Prev by Date: Re: [newbie] Multi-window applications?
  • Next by Date: Montrealers ( Cocoa coders from Montréal? )
  • Previous by thread: Re: Cocoa/GNUStep Portability (was Re: Seattle???)
  • Next by thread: Re: Centering an NSImageView in NSScrollView (again)
  • Index(es):
    • Date
    • Thread