So the problem here is I need a totally different layout in landscape and portrait. For instance, I have a view that in portrait is on top but in landscape is on right of the screen.
I am currently using hard coded frames and I will change views' frames in "viewWillLayoutSubviews" but I don't like this hard coding, is there any way to achieve the same thing in Interface Builder ?
Thanks,
Try implementing updateViewConstraints to first removeConstraints then addConstraints for either portrait or landscape depending on the orientation.
Related
For various optimization purposes, I want to get the device's max display size without the safe areas for both portrait and lanscape.
I can use the UIWindow's safeAreaInsets, but that only gives me the current safe areas, not the one for opposite layout (assuming there is only portrait and landscape).
I had a look at UITraitCollections (I really thought I could achieve it with it), but it seems like a dead end.
Anyone can help me with that ?
Thanks!
I've to develop an iPad app that should have a layout for portrait and a layout for landscape. This app should be able to work with iOS 8 and iOS 9. To design two different layout should I use 2 storyboards: one for the portrait layout and one for landscape layout or I can use only one storyboard with size classes?
I found this solution over stackoverflow, but I'm not sure if it's the right way to work with 2 different layout. Does anyone have an idea about how to work with a portrait layout and with a landscape layout with iPad? So you think it's better to use size classes or to use 2 different storyboard: one for landscape and one for portrait
As per your question you need to use size class for creating application. But in traitCollection you will only get wRegular-hRegular for both landscape and portrait.
result of log value of trait collection with statusBarOrientation.
All you can do is add make constraints active and inactive in
-(void)updateViewConstraints {} method based on [UIApplication sharedApplication].statusBarOrientation.
First you need to bind the constraints you have given to the view and make their objects in .h or .m file.
Then you need to change the constant value of the constraint or make constraints active and inactive based on your requirement.
Result:
1.) iPad Portrait View
2.) iPad Landscape View
This is one way by which you can layout in iPad. Hope it helps you solving your problem.
I have been debating with my boss which of the following is a better way of accounting for an iPad device orientation changes:
Rotating / resizing all views as necessary / making sure their autoresizingmasks are set correctly
In IB, having 2 views pre-made: 1 as the portrait view, and 1 as the landscape view, and, for each orientation change, saying self.view = _ (based on which direction we land on).
Not sure which is better. I just feel like option (1) uses less memory than (2), but can be slightly more tedious?
Any ideas / other pros or cons for either approach? Thank you all in advance.
Actually you should use both:
Use autoresizingmasks when the content of the view is the same and all you need to do is make sure that the content is properly re sized and properly positioned, for this definitely you can use autoresizemasks or springs and struts in xib files
Use 2 different xib files when your content is not the same(extra/less views and the view positioning is really different) for landscape and portrait.
I am working on an iPad app and want to support both portait and landscape orientation.
Currently, I am seeing three ways to handle orientation:
1) Apple recommends using two view controllers (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html)
2) The Beginning iPhone Dev book I have uses a single xib file with multiple UIView (one for portrait, one for landscape), swapping the view in the willAnimateRotationToInterfaceOrientation() method.
3) Others have said the "proper" way to do it was using layoutSubviews and autosizing mask.
Before, when I build an app, I would write my entire app purely in code, including interface setup and layout. The result was I ended up with a massive and very painful to tweak interface code.
Now after writing a number of apps in purely code, I kind of appreciate why there is Interface Builder - to help manage the interface and more so, a view controller should ideally only be for managing data and sending it to the views, not managing how the views should look.
Using Interface Builder, it makes sense to have two separate custom UIViews, one for portrait and one for landscape but I've been told otherwise that layoutSubview is the better option.
But if I were to use layoutSubview, that would mean I have to go back to writing and managing my interface using code, which doesn't seem right to me.
Is using layoutSubviews() really the way to go ?
I really don't see any benefit it has over other method. Some say layoutSubviews allow you to animate the transition to the other orientation.
My two interface isn't a simple resize button or text width when the device rotates. I have adjacent sliders next to text fields that should be stacked vertically when rotating to landscape and other sliders that needs to be moved to the other side of the screen etc.
edit
might be a duplicate questions of:
Handle iPhone orientation Landscape/Portrait
iPad/iPhone multiple orientations best practice?
Moderators can close if need to.
I want to minimize the amount of code I have to write, and use storyboards in xcode to specify the way the view should appear when in both portrait and landscape views.
What is the best/recommended way to do this that minimizes code? I've done some research, but am having trouble finding a simple solution..is it necessary to do some conditional segues, and re-hook up everything in my landscape view, or is there a simpler solution? Thanks!
Generally you define the autoResizingMask (or go to the size inspector in Interface Builder, as shown below) so that the controls will move or resize as the screen size changes. If you do that, you'll generally have pretty decent support for both landscape and portrait. You'll only have to do programmatic changes to the controls' frames if you do some fairly significant changes on orientation changes (e.g. you want to shuffle the various controls around so that they are in very different positions with respect to each other when you change orientation or you want to load very different UIImages). But 90% of the time, autoresizing settings can handle simple moving/resizing/recentering of controls for you: