I need to display NSImageView on resizable NSWindow. The image displayed in the view should scale down if it's too big to fit image view in the widnow and it should also change its size when resizing the window. I am able to achieve correct behavior using Auto-Layout, and setting imageScaling property of NSImageView to NSImageScaleProportionallyDown. Unfortunately it's not working when my image view's imageFrameStyle property is set to NSImageFrameNone (it works for any other option like NSImageFramePhoto or NSImageFrameGrayBezel). I don't want any frame to be displayed, like with NSImageFrameNone, but disabling the frame breaks autoresizing - it looks like with frame set to NSImageFrameNone image is not scaled down and NSImageView is scaled up to match displayed image size. Anyone have solution for that issue?
It occurs that it's easier than I thought. The problem was with Auto-Layout, not with NSImageView scaling logic. Using InterfaceBuilder with my image view selected I had to change "Content Compression Resistance Priority" to lower value (it's located on Size Inspector tab in Xcode5). That solved my problem and the image is now scaled properly when resizing window.
Related
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?
Check this URL http://krystalrae.com/
Scrolling down you will see a girl's cloths are changing on mouse wheel scrolling.
I have to create a iPad application where 3 images will appear likewise. The difference will be that in my case image change will occur horizontally rather than vertically in website. Also, i have to make it inside UIView with events touchesBegan, touchesMoved, touchesEnded and touchesCancelled
Help will be appreciated.
Thanks.
From your comment I gather that the problem is the resizing of the images in UIImageView when changing the bounds of the view.
You can set the contentMode of the image view to something else. The default is UIViewContentModeScaleToFill which is not what you want.
You could, for example, set the lower image view to UIViewContentModeBottom, and the upper image view to UIViewContentModeTop.
Don't forget to make sure your image views have sett the property maskToBounds set as YES.
When making a photo viewer app found that our UIImageView controller is drawing its image outside its frame when the content mode is different neither ScaleToFill nor Aspect Fit.
Trying to understand why; I isolated the problem making a new project which only has a UIImageView with the following frame (50,50,100,100). The image size contained in it is (4592,3056).
After running the app, with the content mode set to ScaleToFill and AspectFit it all worked as expected:
But after setting the contentMode of the UIImageView to TopLeft, the image is drawn outside its frame, the odd thing is that the log from the frame after all has been drawn is still the original {50,50,100,100}.
I've try to understand the issue by moving the Autoresize, the clips and the content mode of the UIViewController but the result is the same.
set clipToBounds = YES on the view.
its NO by default because that makes drawing way cheaper
This is the case:
I have an image. In the projects browser it looks good.
/but when I 'load' it in one of my controls the edges get rather blurry. And I'm not resizing it or anything. Why is this?
The image, unloaded:
The image when loaded in a control:
As you can see the corners get rather blurry/streched. Why?
It happened to me in the past.
Most of the time the problem is that the dimensions of the image are different from the dimensions of the controller.
Check you controller size with:
NSLog(#"controller size = %#",NSStringFromRect(your_controller.rect));
And see if it the image size fits.
I've also had this before and as #shannoga said if the dimensions of the view are different to the image it will auto stretch it.
Are you loading the image into an ImageView? if so the imageView.Mode property defaults to Scale To Fill. If you set the mode to Top, Left or Center it wont stretch the image.
I am using interface builder to create my create my .nib file. THe first thing I did was to add an UIImage view to cover the screen with a background image that serves as part of the interface graphic. Everything was working fine, now the image is shifted up slightly in the simulator. THe Status, Top, and Bottom bar are all "Unspecified". Has anyone encountered this issue and found a way to resolve it?
Is the size of your view in the nib the same size as it will be in the simulator? If it's smaller, your autoresizing masks may be centering it vertically. Verify that it's the correct size, and then verify the autoresizing masks in IB are set the way you want them to be.