Reputation: 584
So I have been moving parts of the code to use constraints rather than the older way of doing things using frames. This is the current code that I need to move. I need to change the height of the view when I hide\unhide the tabbar below when the user presses a button.
CGRect newFrame = self.view.frame;
newFrame.size.height += 44
self.view.frame = newFrame;
self.view is the UIViewController. I want to set the height of the view shown in the picture. There is no way to add a height constraint to it (you can set it on the subviews though easily which i dont want)
I don't see a way of setting the self view height using constraints.
thanks arpit
Upvotes: 0
Views: 797
Reputation: 9337
This short tutorial will be helpful for you.
You can do it using VFL (I personally prefer, see link above) or by this kind of code:
[yourView addConstraint:[NSLayoutConstraint constraintWithItem:yourView
attribute:NSLayoutAttributeHeight
relatedBy:0
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:requiredHeight]];
This piece of code will add a constraint on height for yourView
specified by requiredHeight
. Before start coding please take a look at intrinsicContentSize and updateConstraints methods.
When setting constraints please remember to firstly set (for a view you will set constraints) translatesAutoresizingMaskIntoConstraints
flag to NO (it is set to YES by default). Also reading this should put some light on the topic.
Upvotes: 1