Top space on device rotation - ios

I have the following constraints on my UIView in portrait mode:
And landscape:
This is screenshot of the ViewController when I open it first time:
Top space is OK.
Then I'm rotating the device to landscape:
Do you see that white space on the top?
And when I'm rotating it back to landscape, the space still stays:
Why and how to fix it?

Try to uncheck Adjust scrollview insets Of viewcontroller attribute
Source Of Image: Here

You might have set TopConstraint of your view With margin.
Uncheck box for Add to Margin.

Considering black view about the imageview which contains Back button is a UIView (says, viewNav)
Constraints for viewNav:
if you'r changing the height of viewNav of rotation then use size classes as see below and click on landscape option. Now select your navView and click on height constraint and give c-c constraint like this
Constraints for UiImageView:
If you'r image covers the complete screen the give bottom constraint as 0.
This fixes every thing.
If you are using native navigationBar then you there will be no viewNav and now constraint for image will be
On giving top constraint, don't forget to select use standard value for top constraint then enter 64. Bottom and height is according to your need whatever you prefer.

Related

Swift UIView disappearing from Stack View

I have a label, an Image View, and a button in a vertical stack view. The alignment is set to fill, and the distribution to equal spacing with an offset of 10. On my storyboard, the label appears on top, the image in center, and the button at bottom.
However, when run on simulator or device, the UIView is stripped from the view entirely, so the label appears at the top of the screen, and the button directly below the label.
My only constraints are set on the stack views to the superview
Edit: Forgot to mention the UIImageView is inside of a UIView
I had a similar problem. My UIView in my UIStackView had only a Width constraint and would disappear at runtime. I found I could make it show up again with either of these options:
Add a Height constraint
Add a Top and Bottom constraint
I was having the same issue with a tableview in a stackview. Added the Height constraint to the view and it worked now everything shows fine
Setting a Y constraint on the UIView border caused it to appear when hitting the play button, but it grew outside of the screen bounds.
I had to set size constraints on the UIView in order for it to display properly.

How to force a MapView to cover all space on ViewController?

I need to show a map view to cover all spaces on the screen. I have added constrains as follow:
First I added this:
But it didn't work. Then I tried suggested constrains or tick Width and Height in above picture but still I have 2cm empty space on iPhone 6 as you can see in following image:
Uncheck constrain to margins and then add the constrains again (0,0,0,0).
Note your size class is Compact Width and Compact height
That is for 3.5,4,4.7-inch in landscape
You should choose any any
Then add constraints like this
Your size class is wCompact hCompact.
Change it to wAny hAny to get the desired output.
Opt to uncheck Constrain to margins option and add 0,0,0,0 Spacing to nearest neighbour
Do not fix its height or width els it would remain constant irrespective of iphone screen size .
U can also refer this link for more appropriate auto Layout concept.http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1
Hope it helps.. Happy Coding..:)
You should do Leading, Trailing, Top, and Bottom to superview. Do this by control dragging from the MapView to the view. Just make sure that you have MapView taking up the entire view controller in the storyboard when you apply these constraints. Or, do it programmatically.

Change view width with autolayout and size class enabled

I have done sample screen for iPhone5s with autolayout and size class enabled in swift.I have a view at top of the screen which has 320(width).How do i automatically increase width of view for iPhone6 and iPhone6Plus screen.any help will be appreciated.thanks in advance.
If you want the dimensions of your view to follow the same width as the one of the iPhone it's running on, in Interface Builder, position the view, size it so that it basically looks as you want it to look, and then add the constraints, ctrl drag from your view to it's superview and add "Leading space to container margin" and "Trailing space to container margin" constraints.
You don't set the width. You make constraints to the left and right edges of the superview so it will always be the width of the screen (assuming that the superview is the controller's self.view).

Resize proportionnaly between iphone 4 and 5 screens with XCode

I am trying to use auto layout in x code to correctly resize my view to switch between iphone 4 and 5.
I have a similar problem as the one presented in the picture. Let's consider the UILabel at the bottom is fixed.
I want the top UILabel to be at the middle of the space between the navigation bar and the bottom label. I don't know how to add a constraint that says "top space and bottom space must be equal". As a result, I can only fix one of the two constraints and I cannot get the expected result.
Thanks
The way I do this in IB, is to embed the top label in a UIView. Give that view a standard vertical spacing constraint to the top layout guide, and another to the bottom label. Also give it a fixed width. Give the label centerX and centerY constraints to this view, and it should keep it centered in different screen sizes.
How about adding a container view that fills up the space between the 1st label and the navigation bar, and then center the 2nd label inside the container view.

Desgin ViewController with Storyboard

I design the ViewController include 1 UIView and 1 button in it but when i deploy in the Emulatore, it 's not the same as what i see in storyboard file.
This is a consequence of the auto layout constraints you have. The default screen size in the storyboard is for iPhone 5, but the default simulator is an iPhone 4 size, so by having fixed distance to both the top and bottom of the screen, the view has to be squished to satisfy the constraints.
To fix this, you should give the view a fixed height (from the menu, Editor --> Pin --> height), and then delete bottom constraint.
You can also use distance to superview to top, also set the virw height constant. You dont need the bottom constraint

Resources