16

我有一个视图出现在其父视图纵向模式的中心,我应该使用什么 autoresizemask 以便它也出现在横向模式的中心。它的大小应该保持不变。我只是希望它的原点应该在该点自动移动,以便它出现在中心。请帮忙?

我给了

[parentView setAutoResizesSubview:YES];

parentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
4

3 回答 3

29
// horizontal
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

// vertical
childView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

// both
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
于 2012-10-20T07:12:58.173 回答
3

斯威夫特 3:

childView.translatesAutoresizingMaskIntoConstraints = false

childView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin]
于 2016-09-30T08:31:34.813 回答
0
If you are using swift:
// horizontal
childView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin]
// vertical
childView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin]
// both
childView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin]
于 2016-09-20T22:10:56.560 回答