Suppose I have two Text View. In portrait mode, I want these one below another & In landscape mode, I want these to be side by side
Is it possible to do that using layout constraints in storyboard using autolayout? If yes, then how? If not, then what would be the other better solution to achieve this.
ios6 is my target version
Here's how you might go about it in code.
Basically you need to:
a) configure the appropriate
NSLayoutConstraint
s for the given orientation inupdateViewConstraints
in yourUIViewController
.b) call
[self.view setNeedsUpdateConstraints]
when the interface rotates.Below is a ViewController implementation and a category on UIView with helper methods.
Put this in UIView+Constraints.h
This is UIView+Constraints.m
You could achieve such behaviour by using Interface Builder only. You need to set up some constraints with different priorities.
See my more detailed answer on the topic here. Also there are a screencast and a link to an example app I've created.
In my opinion the best way to layout viewController's views in more than one orientation is to create few views for each orientation. Here i have found this:
"When you add a view controller to the storyboard it comes with a view. Call that the container view. Add two views to the container view: a portrait view and a landscape view. Set the dimension of the portrait view and the landscape view appropriately using the size inspector. Add buttons, more views, labels or whatever to the portrait and landscape views as needed for your application. Then when the orientation changes hide one view and show the other."