Using autolayout for different positioning Portrait vs Landscape - ios

I'm very new to Autolayout. I'm building an iOS 7 app with Xcode 5 and I want realize a login page that appears in a way in Portrait and in another way in Landscape.
This is what I want:
The problem is that I have problem to set the elements in different position for Portrait among Landscape.
Without using autolayout, this is very easy by using hard coded position programmatically, but I want use autolayout.
Can anyone explain me how to achieve this ?
I also read the Ray Wenderlich tutorial, but doesn't explain a case similar to mine.
And I also read this post.
Thanks.

Related

iOS 8 Adaptive layout and constraints on custom design

I am trying to use Adaptive Layout to upgrade my project for iOS 8-9.
I have read and watch a lot of tutorials but all of them are explaining how to adapt a simple design with rectangles and centre them on the screen.
I don't know why I find it so difficult to understand how it works for my design.
This is my design in storyboard and how I would like to appear on all of the iPhones in portrait mode:
Can someone guide me how to properly build the constraints on this View? I might be able to understand the logic of constraints for real designs rather than rectangles which are centred in the screen. shall I start to design from Compact&Regular?
Here are the views laid out for different iPhone screen sizes in portrait mode. I have made some assumptions about the rules for the placement of the views. You can see the constraints also in the screen print.

IOS 8 Adaptive Layout. Different Layout for ipad orientation

Can some one please give me some idea of how to use universal storyboard to show different layouts for iPad portrait and landscape.
Not possible at the moment. I have filed a bug report as wanting a new feature to be added to make it possible. I'll keep you updated.

How to fix the orientation issue in IOS 7

Orientation problem is present across the app. All the views looks fine in portrait mode.
But When orientation changes to landscape mode the subviews are rearranged.
I am using buttons and labels on the view. How to fix the orientation issue so that view for portrait and landscape looks same?
You can do this with springs and struts or using autolayout.
Please refer these wonderful tutorials for getting a hangout of autlayout and its advantage over springs and struts :
Beginning Auto Layout Tutorial in iOS 7: Part 1
Beginning Auto Layout Tutorial in iOS 7: Part 2
Feel free to comment below if you have any doubts regarding the same.
Hope this helps! :)

UIViewController Size doesn´t work

Hi im currently developing an Universal app for iPhone, iPod and iPad. I have all view controllers in both storyboards set to Inferred. It works fine on iPhone Retina and on all iPads but when you put it in landscape mode it gets all messed upp and on the iphone 3,5 inch simulator the bottom gets cut off. How can i fix this? Do i have do create seperate view controllers for landscape mode and iphone 3,5? And the write some code that recognizes if its in landscape mode and iphone 4? I thought this worked automatically. Or have i done something wrong?
There is no quick fix/answer to your question.
Since the screen size is different while using horizontal and vertical orientations - it is simply not the same canvas and thus you will need to do some manual work to set it right.
Strategy 1.
Assuming your layout is simple - there are not too many elements and all elements can theoretically fit both horizontal and vertical screen size:
You should use auto layout from the Interface builder - Look at an excellent video from WWDC
https://developer.apple.com/wwdc/videos/
(video 406 - Taking Control of Auto Layout in Xcode 5)
In few words - you set spacers to your elements, aligning them to the end of your view (dynamically), therefore you can make your element shrink and move automatically respecting the current screen orientation.
Strategy 2.
Assuming your UI is complex and will not fit both orientations:
have a different xib file for horizontal and vertical views, this can take some time, but it is a solid solution that always looks good.
You simply need to track changes in orientation and load the appropriate xib.
Your problem will only be solved if you use Autolayouting and for that you need to go through some tutorials
Ray's Tutorial
Another Very well explained tutorial
Going through the above articles will definately help you in solving your problem

portrait layout wont scroll in landscape orientation

Im quite new to XCode and Interface Builder, so forgive me if the solution is obvious.
I have designed a nice portrait IPhone view in interface builder (XCode 5) and have set the constraints on each of the elements (labels, text views, switches, buttons etc) so that they are positioned correctly in either 3.5 or 4 inch portait mode in the simulator.
However, when I rotate the simulator to landscape it breaks the design with elements overlaying each other and other elements disappearing (being clipped from the view) - and I expected this.
My idea of a solution is to put all of the UI elements inside a UIScrollView and set constraints on the scroll view so that it fills the screen in either portait of landscape mode.
After doing this, the portrait view is as before in the simulator, but in landscape view nothing scrolls, and none of my UI elements respect their constraints (stretch horizontally etc). Im still losing UI at the bottom and I cant scroll it into view.
I assumed that putting everything into the scroll view would simply 'fix' this issue, but the scroll view seems to do absolutely nothing at all. I have fiddled with various settings in interface builder but nothing fixes this.
There seem to be lots of long-winded solutions to this type of scenario based on code, but surely something this simple and common should just 'work'
What am I missing, or what have I done wrong, or does simple scrolling really have to be extensively coded in order to work ???
Putting all of your elements inside a scroll view won't really solve anything. Those elements would still need constraints to know how to position themselves in the scroll view. You need to be careful as well, as this solution sounds like something that goes against apples human interface guidelines. I'd advise against ignoring those, as Apple are known to reject apps that do this.
I'd say your problem is your constraints simply aren't setup correctly if elements are cover other elements and moving into the wrong places when rotated.
Annoyingly the WWDC videos section of the developer site is still down, but when it's back up, have a watch of the video of autolayout in Xcode 5, it will help explain what's going on.
If you want elements to completely change position when rotated however, you're likely to need more than just constraints, and would need to throw in some code to handle the transition between portrait and landscape. So it really depends on what the view is supposed to do when you rotate the device
OK, Ive figured it out. It IS a bug in either XCode 5 or IOS 7
I created 2 simple iphone UI's in interface builder - one in Xcode 4.6.3 targeting IOS 6.1 and the other in XCode 5 Beta 4 targeting IOS 7 beta 4.
The first app ran entirely as I had assumed, with the scroll view scrolling in landscape mode. The second app had no scrolling at all in the scroll view - so obviously a bug.

Resources