haisergeant
haisergeant

Reputation: 1111

iOS layout: push UIView below automatically

I have a view with multiple subviews (UIView, UIButton, UIImage). For example: If I tap on a button, a UIView will expand its frame, and I really want all the components below this UIView will be relocated below this view.

Is there anyone have this problem before? Is there any good approach rather than relocating all subviews by code?

Thanks

Upvotes: 0

Views: 125

Answers (2)

Fabio Felici
Fabio Felici

Reputation: 2906

You can use autolayout and constraints. Set height constraint on the UIView that expand its frame and vertical space constraints on other subviews. Change the constant value of the height constraint and the other subviews will move respecting space constraints.

Upvotes: 1

Shamsiddin Saidov
Shamsiddin Saidov

Reputation: 2281

U can use autoresizingMask property for your subViews. Example:

myButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;

And when you expand your content UIView's frame, this button keeps it's position at the bottom of it's ContentView automatically. You don't need to change the myButton's frame.

Upvotes: 0

Related Questions