Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper AutoresizingMask

I have a view that appears at the center of its parent view portrait mode, what autoresizemask should I use so that it appears in the center in landscape mode too. It's size should remain same.I just want its origin should shift themselves automatically at the point so that it appears at the center.Any help please?

I have given

[parentView setAutoResizesSubview:YES];

parentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
like image 315
Vishal Singh Avatar asked Oct 20 '12 07:10

Vishal Singh


People also ask

What is Autoresizingmask?

An integer bit mask that determines how the receiver resizes itself when its superview's bounds change.

What is a view's Autoresizing mask?

Autoresizing masks is a layout method using a bit mask, or an encoded set of flags, that defines how a view should respond to changes in the superview's bounds. The properties available in a autoresizing mask on a view are: Flexible Top Margin, meaning resizing can change the view's top margin.

What is a view in Swift?

Views are the fundamental building blocks of your app's user interface, and the UIView class defines the behaviors that are common to all views. A view object renders content within its bounds rectangle, and handles any interactions with that content.


2 Answers

// horizontal
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

// vertical
childView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

// both
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
like image 135
Christian Schnorr Avatar answered Sep 19 '22 20:09

Christian Schnorr


Swift 3:

childView.translatesAutoresizingMaskIntoConstraints = false

childView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin]
like image 37
Vladimir Zivanov Avatar answered Sep 20 '22 20:09

Vladimir Zivanov