I am very unexperienced and rather new to Objective-C and I'd like to ask a methodical question. What I want to do is:
- Load a user provided image to show on the screen. The user should be able to zoom. So it seems best for me to use a NSScrollView to draw the image. I have some other demands about the behavior
- When the image is loaded, it should fit the NSScrollView without being stretched in either direction.
- When the user now changes the size of the NSScrollView (via changing the size of the window) the image should be resized appropriately.
- If the user at some point zooms the image, it shall not be resized when changing the size of the NSScrollView. If the image is zoomed to fit into the NSScrollView (means like when loaded) it should be resized again when changing the size of the NSScrollView. I think this is the same behavior as in Apple's preview app.
I guess this is easy to achieve for an experienced programmer, but I have some issues. Here's what I have tried.
I load the image via
[[NSImage alloc] initWithContentsOfFile:imagePathStr];
on a button click. I am also able that it is displayed to fit nicely (on load) into the NSScrollView by changing the size of the image before drawing it. But I can't get the behavior right on resizing or zoom (I use the NSScrollView biuld-in zoom ability). Can someone provide some kind of list of key points that needed to be executed to achieve what I want? Or do someone rather see my explicit code to tell me what I am doing wrong?