We are updating our Auto Layout-using app to natively support iPhone 6 resolution. We added the iPhone 6 launch image, and most of the views scaled nicely.
However, we are experiencing a small annoyance: when loading new view controllers, the views have the iPhone 5 resolution on the UIViewController's viewDidLoad method. The view only gets the iPhone 6 resolution when you hit viewWillAppear.
Why is this? Is there anything we can configure or modify to make the views have the final resolution on viewDidLoad already?
I think the right place to get geometry data from your views is in the method:
- (void)viewDidLayoutSubviews;
This is called when auto layout finishes laying the views. Please beware this method can be called multiple times, i.e. after a rotation of the device.
EDIT
In interface builder, there is an option to set the size for the simulated metrics. I'm not sure if this has to do only with what interface builder displays, or also with the frame of the view at load time. Maybe you can change it and give it a try.
Related
I have been creating an application for iPhone and iPad. I am using Auto Layout (wAny and hAny). Now I want a separate design for iPhone 4s alone. How can I use separate designs for this device. I already completed most of the designs with this wAny and hAny. How can I change this.
Edit:
I want to change only few view controller not all the designs.
I suggest not to go with different storyboards. You can add 2 views inside that viewcontroller's(for which the design is different) view and toggle it programmatically depending on the device. Regarding autolayout, set wAny and hAny and add constraints accordingly.
VC.view
-iPhone 4 View
-Other device's view
This can be done in storyboard only.
So programmatically when loading the vc, check the device and show the specific view hiding the other view. In this case in future, even if the design is normalized, you can easily use the same view with change in one line of code.
This is necessary if the design is totally different. Or if it's just few sub views which are different, I think you should write some code to hide and unhide the subviews acc to the device.
I am a novice in iOS, please correct me if I am wrong anywhere.
Better to go with design it as separate controls if you have design changes and load it conditionally for 3.5 inch screens . If its a simple changes (easily managed through codes) then go with codes itself.
I am trying to wrap my head around the new size classes in iOS8 and XCode6. I am attempting to create a nib, without a storyboard, and do something really simple--center a UIView on the screen.
Starting with a nib in the default size: w:Regular h:Regular, I place a 200x200 UIView onto the parent view and center it, then add contraints to pin it. In my preview pane, the UIView only shows up on the iPad view.
I need for this view to show up on iPads in lanscape and iPhones in portrait. I suppose some day i will understand why Apple thinks this is so much easier, but at the moment I'm bewildered.
When I switch my design view to any of the iPhone supported modes, the UIView disappears.
Even when I unpin the UIView and move it around in the design view, it never shows up in the iPhone view. In other words, I've tried everything to get this view to appear on an iPhone and nothing works.
Here is my UIView and settings:
Obviously there is something I'm missing, but I'm getting really frustrated trying to figure it out. Can anyone offer a clue? Thanks!
It's because you defined your view only for the size classes Regular & Regular. For them to show up on the iPhone you will have to configure the view also for the appropriate size classes, which in case of the iPhone is Regular & Compact where (<height> & <width>).
UPDATE:
The views generally only show up in the size classes for which they are configured. You currently have Regular & Regular selected, this can be seen from your screenshot. This means you defined it only for the devices with size classes Regular & Regular, which is the iPad in both orientations.
You need to add the views also in the size class that you are targeting, which are the size classes of the iPhone.
When I add a UIViewController to a storyboard in the latest xCode its view is defaults to 600x600 in size. This means centred items appear off to the right and the view extends off the bottom of the screen. Why is this?
Many thanks,
Ben
in Xcode 6 the interface builder works with AutoLayout. So you need to set constraints to your views to be in the right place. See here how thats works: Click me
But you also can disable the size class to work in the exact ViewController like this:
If you turn size classes off you see an window like this:
Just select the size class you want (iPhone for example) and you can work like you want it.
But I would recommend to work with AutoLayout due to the fact that there are a lot of different device types (iPhone 4(S), iPhone 5(S), iPad).
I have made an app and it works really great on iPhone simulator 4 inch screen.
But, when I run it on the iPhone 3.5 inch screen, it cuts the bottom of my app
How can I optimize my app to the 3.5 inch screens?
(note :I am using storyboards)
Open your storyboard, then select one of the view controllers. Change the size of the screen to 3.5" as shown here:
Make sure your views are laid out correctly. You may either use Auto Layout or, if you're not using it, check the view sizes, and the springs and struts:
Here, you want to make sure that you don't hardcode the view height to 4", or doing anything similar. After you make the fixes, you can switch back to the 4" size, to make sure the views are still laid out. Repeat for all your view controllers in your storyboard, until done.
If your code updates the UI (e.g. by adding/positioning/animating views), you also need to make sure you're not hardcoding any view's frame with the assumption that the screen is 4".
First option is to use autolayouts.
Second option is to set your views scale properly.
by clicking on a button i selected, you can see how will your layout look on different screen sizes
Now, you select a view you want to set-up, and play with this option here, marked on the picture below
I'd would like to see how the controls on my xib behave without actually launching the app.
In the Xcode documentation it says "[t]o test the behavior of Auto Layout constraints when you are editing a nib file, hold down the Command key and resize the window."
Does this only apply to OS X or is there a way to do it with an iOS app as well?
In xcode 5 you can preview how your view will look in different device screen and OS's. Open the assistant editor (Command+alt+enter) set it to preview and select the viewController you want to test. In the preview tab you can change screen size and iOS version.
What I have found to work is to switch your view controller under Properties -> Simulated Metrics -> Size to Freeform.
Your view should now be resizable with the mouse and the constraints will be in effect during resizing.
If you are designing full screen view, you cannot scale it but you may apply retina 3.5-inch form factor to view it in different height.
If you are putting views in container like UIScrollView, you may rescale the container to see if subviews moving or resizing as designed.
It is powerful when you are designing stand-alone xib for cell or custom views.