質問

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;
役に立ちましたか?

解決

// horizontal
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

// vertical
childView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

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

他のヒント

Swift 3:

childView.translatesAutoresizingMaskIntoConstraints = false

childView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin]
If you are using swift:
// horizontal
childView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin]
// vertical
childView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin]
// both
childView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top