Centering an NSImageView in NSScrollView (again)
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.