iPhone 4 & 5 Autoresize Vertical Space - iphone

I built my views in Interface Builder for iPhone 4 dimensions. I thought that the Autoresize Constraints in iOS 6 will take care of the resizing automatically. The screenshot shows the Top Space constraint that Xcode added automatically. It says that the relationship between the top and the bottom orange view must be 332 points.
When viewed in iPhone 5, the orange button is stretched all the way to the bottom as you can see in the screenshot below.
When changing the relation to Greater Than or Equal, the view does not change and remains the same. When removing the constant to make it Auto, the view is stretched across the entire screen. How do I specify a constraint were the height is 44 points and at the bottom?

Don't have a constraint to the top of the superview. Pin it to the bottom of the superview, and fix the height to 44, then delete the constraint linking it to the top of the view.
You achieve the pinning by selecting the view in question and using the pinning menu in interface builder (the floating menu with three icons on it, or editor-->pin from the menu bar).
To move between 3.5 and 4 inch displays, you need to link content to the correct edge of the superview. Stuff at the bottom should be stuck to the bottom.
I have written about constraint editing in interface builder here if you're interested.

Try adding your own contraints (user constraint), In Auto Layout for each object there must always be enough constraints to determine both its position and size on different devices screen.
Interface Builder automatically creates constraints for you as soon as you place a view in a layout. Try placing your views along IB’s automatic guides to help it guess correctly which layout you want.
Prior to Xcode 4 it was done by setting the springs and struts from the Interface Builder and the springs and struts model is still the default, so for every programmatically created view that you want to use autolayout with, dont forget to call
setTranslatesAutoresizingMaskIntoConstraints:NO.

Related

xibs displayed incorrectly after iOS 7.1 update

So our app is built using XIB interfaces, not story boards. We have XIBs for iPhone and iPad.
Since the iOS7.1 update the, iPhone xibs are now bigger in interface builder and far too tall when deployed on a device.
The height is all wrong, the XIB is far too tall now. For example, backgrounds appear to go way outside the View when set to fill. When deployed on the phone everything is shifted down about the height of the top nav bar.
If I add/remove Top/Bottom Bars for the View in Interface Builder things shift around but not in a way that makes sense. My app has a nav bar, if I tell the interface builder it has a nav bar then the height of the xib grows a further 80 or so pixels. If I tell the interface builder it has no nav bar, everything shifts up properly but the height of the View is still so tall that backgrounds and stuff near the bottom go off screen.
So for the very vague issue but we are pulling hair over this.
UPDATE
- It seems Opaque Navigation Bar fixes half the problem. We had every interface set with a Translucent Nav Bar. Those do not appear to take up space in IOS7.1 but they did in IOS7.0.
The problem now is still height. It still seems internally the height is broken or starts from a new origin.
In view did load, on a view with a opaque nav bar, on iPod Touch:
self.view.frame.origin.y is showing 0
self.view.frame.size.height is showing 256
Nav bar origin.y = 20
Nav bar size.height = 32
This totals 308, missing 12 pixels.
Create auto layout constraints in IB or programmatically that align the top of the main view in each XIB file to the "top layout guide" and bottom of the views to the "bottom layout guide." This solved a very similar problem when moving from iOS 6 to iOS 7 in several of my apps.

How to autosize view without auto layout in iOS

I have a problem that I can't understand resizing views. My deployment target is iOS 5.0, so I have disabled auto layout in the interface builder to make it compatible with iOS 5.0. The view does not resize automatically. Following is an example:
Interface Builder Snapshot:
4-inch screen:
3.5-inch screen (has problem):
As you can see, the button at the bottom of the view goes out of the screen. The background image also does not resize automatically. I can not understand how I can solve this problem. Can anyone help me?
Welcome to the pre-autolayout world! You must set the autoresizing "springs and struts" so that the stuff at the bottom is attached to the bottom of the superview and not the top. So, struts to the bottom, springs to the top. That way, as the superview gets larger and smaller, the stuff at the bottom moves with the bottom.
You could alternatively reposition the stuff in code, but there's no need in this situation.
Here's the section on autoresizing from my book:
http://www.apeth.com/iOSBook/ch14.html#_autoresizing
The part about the superview and the background image not being resized is a different matter. Is this the view of a UIViewController? If so, then if you are putting the UIViewController into the view controller parent-child hierarchy correctly, it will be resized by its parent. But you have not shown any code, so there's no telling what this view may be or how it is supposed to get into the interface.

MKMapView maximized, but I do not want it

I got an issue and I don't know why I have it and how to fix it! Maybe it is only a simple problem. Here are two screens:
There is something missing! Where is the Button? And why is the Map at full screen? It seems a bit strange can anyone help?
This is undoubtedly a function the screen going from a 4" screen when previewing your screen in Interface Builder to a 3.5" inch simulator/device screen.
If using autolayout (open up the storyboard, click on the first tab, the "File Inspector" and see if "Use Autolayout" is checked or not). Check your constraints. The map view should not have a height constraint (or if IB won't let you get rid of it, just drop its priority down to the lowest possible value...though if it adds the height constraint back in, it means that your other constraints are not fully qualified, such as neglecting the button's bottom constraint) but should have either a bottom constraint to the bottom of the screen or, better, to the button. Also make sure that the button's top constraint goes to the map view and that it has a bottom constraint that goes to the super view. Interface Builder makes this process far more complicated than it needs to be in its effort to add what it determines as missing constraints, IMHO, but it can work. It took me 2-3 minutes of fussing with all of the vertical constraints to make sure that they were both unambiguous as well as satisfiable at both screen heights.
If not using autolayout, check your autosizing masks (located on the "Size inspector" tab). You want flexible height and fixed bottom.
In IB you can toggle the appearance of your view from 4.0" to 3.5" by pressing the button. Just adjust your autolayout constraints or non-autolayout autosizing masks and then toggle back and forth between 3.5" screen and 4.0" screen to confirm whether everything is configured properly.

UIViewController Nib Layout changes at runtime

Notice the Nib on the left displays a layout with 2 UILabels, 1 UITextView and 2 buttons. The Y coordinate of the buttons changes at runtime. What is causing this and how do I fix it?
Update #1 - Problem goes away when I shift to a iPhone Retina 4-Inch display.
Update #2 SOLVED - Problem goes away when by unchecking 'Autolayout' in the xib properties.
It looks like you're using iOS 6 and a storyboard with the 4-inch "tall" iPhone screen form factor simulated. Assuming you are using Auto Layout, you probably have a constraint added to one or both of the buttons that pins them to the bottom of their superview. When you then run your app on the 3.5" screen iPhone simulator, the buttons appear to "move up" as their superview has gotten shorter than on your storyboard.
Find the button with the icon pictured below while editing your storyboard, and click it to toggle the simulated screen size between the 3.5-inch and 4-inch form factors. You should see your buttons re-layout based on their constraints.
To set your buttons' spacing relative to the top instead of bottom of their superview, select both buttons and from the menu bar choose the Editor menu > Pin > Top Space to Superview. (Or use the Pin button pictured below directly from the storyboard.)
There's a good introductory tutorial to Auto Layout here, if you haven't learned about it yet.

iPhone 4 to iPhone 5 - toolbar doesn't move to the bottom

I have an app that is designed for the iPhone 4. This app has a toolbar that was drag-dropped in Interface Builder to the bottom of the screen. When testing on simulator's iPhone 5 "device", the toolbar does NOT automatically go to the bottom of the screen.
My question is - is there some kind of a trick or technique, that will let all the UITables "stretch" to populate all the new available space, and toolbars go to the bottom no matter what kind iPhone it is being connected to? It would be painful, to do this programmatically - that is figure out what kind of an iPhone I am and then, programmatically reposition all the ui. If this is in fact a must, should any new iPhone apps be designed for 4" retina, and then programmatically shrink everything for iPhone 4 size, or is it better to design for 3.5", and then stretch and push down toolbars in case it is an iPhone 5 with 4" screen.
Thanks for any input..
If you are only using iOS 6, the easiest method would be to use Auto Layout and add a constraint in Interface Builder. The constraint would describe that the toolbar's bottom edge should be equal to the superview's bottom edge. You don't have to code specifically for a single device. To have the UITableView stretch to fill all the available space, again I would recommend using constraints on the UIScrollView (not UITableView, which sits inside the scroll view) to describe this behavior, e.g. The scroll view's top edge should equal the superview's top, left edge should equal the superview's left, bottom edge should equal the UIToolbar's top (In IB, a spacing constraint specifying that the spacing between the UIToolbar and the UIScrollView should equal 0), and right edge should equal the superview's edge.
If you can't use constraints, this behavior is specified using the struts and springs system that utilizes the autoresizingMask property on the view that specifies that the UITableView's parent-UIScrollView has a flexible width and height and the UIToolbar has a fixed height and a flexible with. You would manually position the UIScrollView and UIToolbar by setting their respective frame property that describes the x,y coordinates of the top-left edge as well as the width and height of the view.
View Programming Guide for iOS - Adjusting the Size and Position of Views at Runtime
Cocoa Auto Layout Guide: About Cocoa Auto Layout