Re: Image Alignment In Scrolled View?
Re: Image Alignment In Scrolled View?
- Subject: Re: Image Alignment In Scrolled View?
- From: "Louis C. Sacha" <email@hidden>
- Date: Mon, 14 Jun 2004 21:47:33 -0700
Hello...
1) The problem is most likely that the image view is smaller than the
content area of the scroll view. Therefore, the placement of the
image is based on where the scroll view is putting the image view,
not the alignment you have set in the image view.
It might be easier to use a NSView containing the image view as the
content of the scroll view instead, with the image view at the top
left of the NSView, with the autoresize mask of the image view set up
so that itdoes not resize and only the space below it and to the
right expands when the NSView is resized. You may need to manually
manage the size of that NSView, if the size of the image view
changes, to get things working correctly.
2) How exactly is the scrolling getting screwed up when you change
the window size? By manually changing the window size, do you mean
the user resizing the window by dragging the corner of the window, or
changing the size of the window programmatically?
3) In general, you shouldn't ask an object about it's retain count,
and you shouldn't base your code on how the retain count of an object
changes when you do something. Using the retain count of an object
just isn't a reliable way to keep track of memory management in your
code...
Following the memory management rules in your code should be your
primary concern. The code in the Cocoa frameworks is responsible for
making sure that it follows those same rules, and any exceptions to
the normal rules should be documented (for example,
NSNotificationCenter does not retain observers and objects registered
with the addObserver:selector:name:object: method, and so that
exception to the rules is noted in the documentation for the method).
Since the NSImageView (or its cell) needs to continue working with
the image beyond the scope of the setImage: method, it is the image
view (or cell's) responsibility to copy it or retain it, and then to
release the image when it is no longer required. There are a variety
of reasons why you might be seeing the double increment of the retain
count (and keep in mind that the value returned by retainCount does
not reflect any pending releases due to the object being in one or
more autorelease pools), and it's probably not something you should
concern yourself with. In fact, it is best not to make assumptions
about whether the NSImageView is using the actual NSImage instance
you passed it or a copy. If you need to make changes to the image in
the NSImageView, you should use the -image method to get a reference
to that image from the image view, instead of making changes to the
original image with the assumption that those changes will be
reflected in the image view.
There are _extremely_ rare cases (bugs) where fiddling with the
retain count might be required as a workaround, but the vast majority
of memory management problems will be in your own code and not the
framework. It's best to focus on making sure your code does the right
thing and only start worrying about the implementation of the
framework as a last resort when you really have to.
Hope that helps,
Louis
Hi,
I am trying learn how to display images in a scroll view containing
an image view.
1) The most trivial of my problems is that small images load into
the lower left corner of the image view...
I have in the code: [theImageView setImageAlignment: NSImageAlignTopLeft];
but it or any other choice for alignment seems to have no effect.
2) Manually changing the window size seems to screw up the scrolling...
Don't have a clue here ;(
3) this code
NSLog(@"ScaledImage release cnt(2):%d",[tmpImage retainCount]);
[theImageView setImage:tmpImage];
NSLog(@"ScaledImage release cnt(3):%d",[tmpImage retainCount]);
generates a log file like:
2004-06-14 19:30:53.395 SimpleImage[8274] ScaledImage release cnt(2):1
2004-06-14 19:30:53.396 SimpleImage[8274] ScaledImage release cnt(3):3
doh!
Any suggestions?
Jerry
_______________________________________________
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.