Proper AutoresizingMask

Vishal Singh picture Vishal Singh · Oct 20, 2012 · Viewed 13.8k times · Source

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;

Answer

Christian Schnorr picture Christian Schnorr · Oct 20, 2012
// horizontal
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

// vertical
childView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

// both
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;