Aling UIView to a UIToolbar using autolayout - ios

I trying to align an UIView to the bottom of a container view(UIScroolView) and above a tool bar.
It works perfectly when design to the iphone 3.5 display but when a change my layout to the 4.0 display, my view doesn't get alined to the bottom instead it stays in the same position with a gap from the UIToolbar.
I checked and i realized the i have a constraint Vertical Space with a constant and i think thats why my view always stays in the same place, the problem is i can't get rid of this constraint, i'd like to know if someone could help me with this one.
thanks!

I think you need to add a height constraint to the toolbar. If you have that and a zero length vertical spacing constraint between the toolbar and scroll view, you should be able to delete that constraint to the top of the super view.

Related

Bottom Constraint with UIScrollView

Im trying to make a dynamic UIScrollView, using this answer I could make it work Calculating contentSize for UIScrollView when using Auto Layout
These are my label constraints:
The scroll is working, but since I have the bottom constraint the view will always have the huge space in the bottom. But if I remove the bottom constraint the scroll will not work. How can I keep the constraint but at the same time don't have all this huge space? Is this possible?
The solution was to make the view inside the scroll view to have the same height as the label so i don't have that huge bottom constrain, doing that solved my problem since the new bottom constrain is now 8 instead of 595.
To get the same size and location of the picture, I suggest to
delete the "595" Bottom Space constraint and instead set a height constraint on the UILabel. This will get rid of all that huge space.

Strange behavior of constraints, iOS8

I have two root views on superview.
All views and constraints I've added from code. Top view have H:|-0-[view]-0-|. Same vfl code have bottom view. Next, top view attached top to top, bottom to top of second view, second bottom attached to bottom. The code is V:|-0-[topView]-0-[secondView]-0-|.
Second view have intrinsic height, so height of both views depends on this value. When I change bottom view height and animate layoutIfNeed all works fine for me.
Next, bottom view have some subviews. Bottom is simple view-container and top is button. Both of them attached to left / right, like H:|-0-[view]-0-|. Bottom view has intrinsic height too, so vertically them attached like outside views, without (!) attaching button to top of superview (V:[button]-0-[secondView]-0-|). Second view is ATTACHED bottom to bottom, but when I animating changing height of this container, its subviews go top on iOS 8.
View hierarchy is
Constraints:
H:|-0-[topView]-0-|
H:|-0-[bottomView]-0-|
V:|-0-[topView]-0-[bottomView(110)]-0-|
H:|-0-[buttonBackCamera]-0-|
H:|-0-[grayView]-0-|
V:[buttonBackCamera]-0-[grayView(85)]-0-| //here is constraint, that MUST attach grayView to bottom.
While debugging, I noticed, that constraint is attached, active and it must work, but :( .
Any thoughts about this?
UPDATE
I've checked this on iOS 8.3, all works fine too.
Make sure bottom view contains constraint from Leading to superview, Trailing to Superview and Bottom to Bottom Guide.
And if you are still facing any issue then go for,
-(void)viewWillLayoutSubviews
{
[self.view layoutIfneeded];
}
I don't think I got the problem entirely but may I suggest you to check the size class that is selected and the size class for each of the enabled constraint.

Why auto layout constraints not working?

I'm setting constraints in IB like
But when i run the app on iPhone4 it shows
Why last three buttons not shown properly on iPhone4 screen?is there any mistake in my constraints ?
Edit:- This is my view hierarchy:-
UITabbarControlle -> UINavigationController -> UIViewController and tab bar controller is rootviewcontroller.
Edit:- FYI there is no effect of any constraints on the screen(basically autolayout not working for me).
You have designed the buttons on 4 inch and you don't have enough space on 3.5 for all of them.
One way to do this is to place scroll view over your view controller's view and add the buttons on the scroll view.You have to add constraint on the scroll view , to be fixed on each side (without width/height).
After that grab all the buttons and add constrains on each side and sizes , so they will be fixed
If you , on other hand, have enough space for all the buttons to fit in 3.5' without any top/bottom margins you can add the button in UIView (instead of scroll view). Place the buttons in the view and set fixed width/height on that view.Center the view and it will keep his size (with the buttons inside on both screen sizes)
There is an issue in your constraints, you have to update them.
You can do as is shown on the image bellow:
Once done, you will see, the Orange lines under your buttons turned to blue.
I wish that helps you!
Your view is probably within a UIScrollView which will extend your total contentheight. It is not related to the absolute height of your viewport.
However, what do you expect? Your 3 buttons would overlay to the next buttons, if your theoretical approach would work.
What you need to to do is to wire all buttons to each other and give the view a top and bottom constraint to the top and bottom layout. You probably need to adjust your view to be on full screen and not to extend to the bottom.
Hint: as long as something is 'yellow' you need to add further constraints.

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.

iOS 6 Autolayout not resizing properly

So all I'm trying to do is put an imageview at the foot of the screen. Before iOS6 autolayout I could just hit the bottom "I" and it would hold it to the bottom and push it up if the screen got short (i.e. if the screen size went from 568 to 480 points tall). But now I have been trying to add a bottom spacing to Superview at 0 but I can't seem to do anything to get rid of the the top spacing constraint to stop messing me up. If I convert the top spacing to a user constraint and then delete it then (thinking that the vertical constraint would be handled by the bottom spacing) but it auto re-creates that contraint... any ideas?
Update It seems it was due to the fact that I was having it be a subview of a scrollview (was going to use it for scrolling horizontally, not vertically). Anyone know why it wont let me do that? Seems like you should still be able to constraint to the bottom of a scroll view.
It could be that the Button's constraints are somehow wrong. Having the height, width, bottom distance and horizontal centering should be enough to define its position. Try deleting the button and centering the image view on the super view instead, and see if tha allows you to delete that top constraint.

Resources