我有一个视图出现在其父视图纵向模式的中心,我应该使用什么 autoresizemask 以便它也出现在横向模式的中心。它的大小应该保持不变。我只是希望它的原点应该在该点自动移动,以便它出现在中心。请帮忙?
我给了
[parentView setAutoResizesSubview:YES];
parentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
我有一个视图出现在其父视图纵向模式的中心,我应该使用什么 autoresizemask 以便它也出现在横向模式的中心。它的大小应该保持不变。我只是希望它的原点应该在该点自动移动,以便它出现在中心。请帮忙?
我给了
[parentView setAutoResizesSubview:YES];
parentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
// horizontal
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
// vertical
childView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
// both
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
斯威夫特 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]