答案 0 :(得分:1)
Any / Compact意味着任何手机的宽度都是紧凑的,iPhone的尺寸小于6+。您需要为Regular / Compact设置约束,以便为Portrait中的6+以外的iPhone设置约束。
答案 1 :(得分:1)
使用UIStackView,这种事情更容易
。有一个good tutorial here;我强烈建议你在做好事情之前先用堆栈视图进行练习。
答案 2 :(得分:0)
你应该给出约束,
top, bottom, leading and trailing
同时查看。
然后选择两个视图并给出equal height
约束,您将获得所需的结果。
你可以在any any
中提供。它适用于每个方向。
希望这会有所帮助:)
答案 3 :(得分:0)
将此添加到您的viewController的 viewDidLoad 方法
UIView *firstView = [[UIView alloc] init];
self.navigationController.navigationBar.translucent = false;
firstView.backgroundColor = [UIColor redColor];
firstView.translatesAutoresizingMaskIntoConstraints = false;
[self.view addSubview:firstView];
NSLayoutConstraint *topFirstViewYConstraint = [
NSLayoutConstraint constraintWithItem:firstView属性:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view属性:NSLayoutAttributeTop 乘数:1.0F 常数:0.0F
];
NSLayoutConstraint * centerFirstViewHeightConstraint = [ NSLayoutConstraint constraintWithItem:firstView 属性:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view 属性:NSLayoutAttributeHeight 乘数:0.5F 常数:0.0 ];
NSLayoutConstraint * centerFirstViewWidthConstraint = [ NSLayoutConstraint constraintWithItem:firstView 属性:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth乘数:1.0f常量:0.0f ]。 [super.view addConstraints:@ [topFirstViewYConstraint,centerFirstViewHeightConstraint,centerFirstViewWidthConstraint]];
UIView *secondView = [[UIView alloc] init];
secondView.backgroundColor = [UIColor greenColor];
secondView.translatesAutoresizingMaskIntoConstraints = false;
[self.view addSubview:secondView];
NSLayoutConstraint *topSecondViewYConstraint = [
NSLayoutConstraint constraintWithItem:secondView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:的firstView 属性:NSLayoutAttributeBottom 乘数:1.0F 恒:0.0F ]。 NSLayoutConstraint * centerSecondViewHeightConstraint = [ NSLayoutConstraint constraintWithItem:secondView 属性:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view 属性:NSLayoutAttributeHeight 乘数:0.5F 常数:0.0 ]。 NSLayoutConstraint * centerSecondViewWidthConstraint = [ NSLayoutConstraint constraintWithItem:secondView 属性:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view 属性:NSLayoutAttributeWidth 乘数:1.0F 恒:0.0F ]。 [super.view addConstraints:@ [topSecondViewYConstraint,centerSecondViewHeightConstraint,centerSecondViewWidthConstraint]];
答案 4 :(得分:0)
所以问题似乎是iPhone 6+之前的iPhone具有针对格局的wCompact hCompact尺寸等级。你应该记住不要使用像wCompact hAny这样的大小类,因为它们会覆盖那个紧凑的大小类。
所以,实际上,在这种情况下你需要创建3个大小的类: wCompact hRegular - 所有肖像 wCompact hCompact - 早于6+的iPhone wRegular hCompact - 所有其他