UIImage View shifting in Interface Builder - cocoa-touch

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.

Related

iOS 7 + Auto Layout: Strange UIImageView behaviour

I've got a strange UIImageView behaviour:
I've got a UIViewController with an embedded UIImageView and a close button. Very basic stuff, done a thousand times. I didn't use Auto Layout that much in the past, but another view controller in the same Storyboard has nearly the same config and doesn't appear as strange as this specific one.
In my Storyboard the Controller looks like that:
...and on the device it looks like that:
That image is 1024x768, so it should be filled to the bounds. Content mode in the image view is Aspect fill. When i dismiss the view, i can see that the upper part of the image view must be hidden at the top with some negative Y or something.
I need Auto Layout in this storyboard, because it's an iPhone + iPad App with both orientations.
Has someone hat a behaviour like that before?
Thank you!
Edit:
Here is the layout panel:
First, get rid of the alignment constraints, they are not needed if you're already anchoring your view to every side with a set distance.
Second, check the mode property of your UIImageView in the interface builder. If the image was not big enough and you had it set for "TOP" instead of, say, "aspect fill", you'd see something like this even though the view is actually covering the whole screen.
I'm sorry that I have to say this, but it was, as you certainly thought, my own fault.
The problem was that I made a photo with the iPad, and the iPad can be used in both orientations in this app. The photo was taken and was then used for an own view that allows the user to put annotations on the image.
The image gets then saved, and that was were the problem occured: I call
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
The landscape image was now taken into a portrait frame. After adjusting this and only allowing portrait mode, everything worked well.
Thanks anyways for your answers. And sorry for asking a question when the problem was another one and my own fault.

NSImageView won't scale image down if frame style is NSImageFrameNone

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.

Specific behaviour wanted when loading and displaying an image in an NSScrollView (Mac OS X)

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?

iOS stretch image to full screen

I have a scroll view with a image view inside. I was wondering whether it's possible to have the image inside the image view be much smaller than the resolution of the screen, and somehow be able to stretch it to fit the screen.
Set contentMode on the UIImageView and change its size.
[UIImageView setContentMode:UIViewContentModeScaleToFill];
Check the docs for more informations regarding UIViewContentMode:
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW69
Sure, just change the bounds of the imageView.
Am I missing something here?
Your UIImageView is within an UIScrollView I understand?
That would work by adjusting the scroll view plus adusting the image view appropriately. However that is not advisable to do. You will get lost in small errors with annoying effects.
I'd suggest to add an additional UIView that can match the bounds of the screen.
Add that view to the underlying "view" object and use the bringSubviewToFront method.
You could as well make sure that this new UIView is the first subview of the most underlying view object. You could achieve that by manipulating the subviews array structure - which I do not recommend in general wihout having fully understood everythng about the view hierarchy.
You can as well achieve that by adding the additional view at first before adding any other view. (Within IB just make sure that the new view is the topmost in the tree, coming next to the view controllers "view".) And then make it hidden until you actually need it. Then you unhide it. When it is not needed anymore then hide it again and neither delete it nor erase it from its superview.

Can a UIViewImage draw its image outside its frame?

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