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

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

Related

Layout for an ios app

I have some issues when i launch my swift application on ipad simulator. I have a home view witch displays 5 images. In my storyboard i have set for all of those constraints for height, width and also spacing. The problem is that when my app is running from ipad , the photo on the middle is situated over the other ones and the spacing is not as i expected.
What i want is a way i can make the same space value between images for each screen size and that the images will resize themselves in order to respect the initial view. Any piece of advice is more than welcome !^.^
Remove width and height constraints for your image views and add equal width and equal height constraints to them. Check out "Auto Layout Tutorial" section "Fixing the width" to see how to set equal width between views. I recommend you to read it whole :)
Nikita is right.
I can add: often apps evolve, so you will add another image.. far better to pass to a CollectionView where every CollectionViewCell owns an image.
In this way:
1) you can decide layout very precisely (with constraints in InterfaceBuilder, or form code using NSCollectionViewFlowLayout delegate methods..)
2) You can manage rotation easily
3) You can scale for iPhone..

iPhone 4 & 5 Autoresize Vertical Space

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.

Keep autolayout view same size in 3.5" and 4"

I have a tracker that is 320 pixels tall that goes in the center(ish) of the screen of my app and I want to place labels in the four corners of the tracker, so I made an invisible view the size of the tracker so that I could align the labels to the view's edges, but autolayout keeps resizing the view when the tracker remains 320 pixels. Is there a way to keep my view the same size (390px) on both 3.5" and 4" iPhone screens?
You can always add fixed width and height constraints to your view. Select your view and then chose Pin/Width and/or Pin/Height from the editor menu. The pin menu is also available from the middle segment in that control thingy in the lower left corner of Interface Builder.
To keep your layout from being ambiguous you then might have to remove some constraints from the size inspector of the utility area.

Can't have a UIViewPicker well laid for iphone 4 & 5

I have one storyboard file for iPhone devices, and in one of the views there is a subview that contains a UIPickerView, and, when it runs on the iPhone 4 the UIPickerView is stuck at the bottom of the view as it should be, but when it comes to the iPhone 5, the UIPickerView appears a little above of the bottom of the screen.
If I fix the problem for the iPhone 5, the UIVPickerView won't appear completely when I run it on the iPhone 4. (half of it appears below the screen)
So is there a way to have the UIViewPicker well laid for both iphone 4 and 5 resolutions?
NOTE: I solved the issue by creating a completely new subview with the UIPickerView. Now it is well laid whatever the device is.
When creating the picker, you need to use the size of the screen to determine the location. It seems like you are just putting in the coordinates for the y manually, which only works when using one screen size.
If your view that you are in is the same size as the screen, as it most likely is but may not be, you can do:
int y = self.view.frame.size.height;
and use that as the y-coordinate of your pickerView.
Otherwise, you can find the size of the screen by using:
[[UIScreen mainScreen] applicationFrame].size.width //if in portrait
//or
[[UIScreen mainScreen] applicationFrame].size.height //if in landscape
Then you have to subtract the height of the navigationController from that if you have one.
If you're using autolayout, you should be able to change the constraints the picker uses to get it to stick to the bottom. Select the picker, click the "H"-shaped autolayout menu icon in the bottom right corner of the storyboard, and choose "Bottom Space to Superview". Then delete any constraints attaching the picker to the top of the screen. If that doesn't work, make sure that all of the picker's superviews have constraints to attach them to the bottom, too; you'll have to decide whether you want them to resize or slide down on an iPhone 5.
I fixed the issue. Not sure what was going wrong but I deleted the subview, then created a new one and added the UIPickerView. Surprisingly, now it is well laid whatever the device is.

Rotating UIView and background to landscape mode

The initial root view controller is 9 (3x3) buttons with a custom background in portrait mode. When the device is rotated into landscape mode the last row of buttons (of course) are cut off and the background (which is 320x480) doesn't fill the width of the screen.
What is the proper way of handling this? Do I need to move and resize the buttons myself? Do I have multiple Nibs? How do I resize/rotate the background?
Use shouldAutorotateToInterfaceOrientation and/or deviceDidRotateSelector in your viewController to reposition / layout & scale your views programmatically as you require.
If you set the auto-resizing masks on the buttons to have flexible margins in all directions they should reposition themselves appropriately when you rotate the device. You can do this either in code, or in Interface Builder (which has a nice little simulator demonstrating the effect)
With regards the background, what I prefer to do is to make the image the combination of the maximum proportions of each orientation, and then center it. For instance, make your image 480 x 480, make the view that houses it the same size and then use the appropriate auto-resizing masks to achieve the desired effect.