Rotating the views when the iPad rotates - ios

really new to iPad development here. I made some mockups for what I'm trying to do.
I have a layout like so with options and menu at the bottom. When I rotate to landscape I want to get something like this:
In landscape the menu bar will always be on the right. In portrait always at the bottom. The contents of the square keep their position and rotation regardless of the device orientation.
What would be the rest way of going about this? I have considered removing all the views as the device begins to rotate and then replacing them using new coordinates. Doesn't seem like the animation will be smooth though. I understand how to do constraints, but I want the top square to stick to the tom when portrait and stick to the left when landscape, not always at the top. Any pointers on this would be really appreciated! thank you

This is a job for size classes. They let you define separate layouts for different orientations and would be an ideal solution for your problem. However, for some reason, the difference between iPad portrait and landscape orientation is not directly supported by the the current implementation of size classes.
There is a workaround, Sizing class for iPad portrait and Landscape Modes, that can redefine the meaning of the existing size classes to fit your problem. In other words, you can use the portrait and landscape size classes for the iPhone and re-map them so that they apply to the iPad.
They are selected by a 3x3 grid in Xcode’s Interface Builder. If you play with it a little, it’s easy to grasp the concept.
Here is a screen capture of the control in Interface Builder that lets you switch among your different layouts:

Related

I am trying to get both landscape and portrait bottom safe area insets at once when the screen is loaded

I am trying to get bottom safe area insets for both portrait and landscape mode together when the screen is loaded. I know how to get the safe area inset for portrait mode when I am actually in portrait mode and landscape mode when I am actually in landscape mode separately.
if #available(iOS 11.0, *) {
let window =
UIApplication.shared.keyWindow
let bottomPadding =
window?.safeAreaInsets.bottom
}
This works good for that but I actually need this inset for both landscape and portrait mode irrespective of which mode I am actually in
Personally I think this is a very valid question. If I'm building a UI that has expensive layout calculations to be made and where the user can rotate from portrait to landscape, I would like to pre-calculate the UICollectionView section layouts for both landscape and portrait while the user is already sitting looking at a loading screen. At that point if it takes an extra half second they won't know or care. But when you rotate the device and the whole UI glitches to a halt that's a terrible experience.
Why are you not using Auto layout and compositional layouts (you may say), well maybe I am, and maybe they still simply don't manage my use cases. So maybe the above question would allow me to build a better user experience.

One landscape view for whole app

How to setup just one landscape view for whole app? I want to show only one view (qrcode) when phone is rotated independently in wich view this happened. What is the easiest way to do it?
My app is in portrait and I want show users code when it rotated to landscape in whatever view this was done.
See this answer. Just untick Portrait and tick on whatever Landscape orientation you want.
http://stackoverflow.com/a/29791531/7198143
Edit:
You should use Autolayout in your Storyboard to set up the right constraints so even in Landscape mode, the label for the code shows up. See this tutorial for more info.
Autolayout tutorial

StackView change to match device orientation

Is it possible to use a vertical stack view when the device is in portrait mode, but switch to a horizontal stack view when the device is orientated to landscape mode, to make best use of space.
Click the small plus button in the attributes inspector to add a variation, in this screenshot I already added one to switch to horizontal when regular width.
See a preview by changing the screen options at the bottom of the storyboard.
Use Auto Layout to design UI, orientation will be taken care of automatically.
See a tutorial here, it should answer your question in detail.

iPad - Different designs for landscape and portrait mode

I'm making an application for iPad in Xcode in template Master-detail application. I need to do a design for portrait mode and another for landscape mode. My first idea was make two UIViews and make a rule: if portrait, show View1, if landscape, show View2. But I have text fields in it and when the user will be typing something inside and then rotate the device, text will be deleted, because it will be another UIView... Can anybody help me, how to do it, please?
You can have one view and use springs and struts or use autolayout.
You can also add views and hide/show them based on the orientation change.
You can change the size and position of the view on orientation change.

landscape and portrait in split viewController

I created a split view controller application. I want to display my buttons and controls in landscape and portrait view differently(only the position).
When I change the orientation to landscape it shows the controls in portrait only. When I click on the cell in the tableview then it will show in correct position. What is the reason for that? Help me please.
I am a little confused about your question, but what I think you are trying to ask is how to change your view if the screen is in landscape or portrait orientation. Without seeing your code it is hard to tell you exactly how to do it, but the general idea (at least how I do it in my code) is that you want to split your code into two parts one that is in landscape orientation, and one that is in portrait orientation. You can tell the difference by seeing if the screen height is greater than the screen width.

Resources